BxTimelineModule.php 140 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Timeline Timeline
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolAcl');
  12. bx_import('BxBaseModNotificationsModule');
  13. define('BX_TIMELINE_TYPE_ITEM', 'view_item');
  14. define('BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS', 'owner_and_connections');
  15. define('BX_TIMELINE_TYPE_HOT', 'hot');
  16. define('BX_TIMELINE_TYPE_DEFAULT', BX_BASE_MOD_NTFS_TYPE_OWNER);
  17. define('BX_TIMELINE_VIEW_ITEM', 'item');
  18. define('BX_TIMELINE_VIEW_TIMELINE', 'timeline');
  19. define('BX_TIMELINE_VIEW_OUTLINE', 'outline');
  20. define('BX_TIMELINE_VIEW_SEARCH', 'search');
  21. define('BX_TIMELINE_VIEW_DEFAULT', BX_TIMELINE_VIEW_OUTLINE);
  22. define('BX_TIMELINE_FILTER_ALL', 'all');
  23. define('BX_TIMELINE_FILTER_OWNER', 'owner');
  24. define('BX_TIMELINE_FILTER_OTHER', 'other');
  25. define('BX_TIMELINE_FILTER_OTHER_VIEWER', 'other_viewer');
  26. define('BX_TIMELINE_PARSE_TYPE_POST', 'post');
  27. define('BX_TIMELINE_PARSE_TYPE_REPOST', 'repost');
  28. define('BX_TIMELINE_PARSE_TYPE_DEFAULT', BX_TIMELINE_PARSE_TYPE_POST);
  29. define('BX_TIMELINE_STATUS_ACTIVE', 'active');
  30. define('BX_TIMELINE_STATUS_AWAITING', 'awaiting');
  31. define('BX_TIMELINE_STATUS_HIDDEN', 'hidden');
  32. define('BX_TIMELINE_STATUS_DELETED', 'deleted');
  33. define('BX_TIMELINE_MEDIA_PHOTO', 'photo');
  34. define('BX_TIMELINE_MEDIA_VIDEO', 'video');
  35. //--- Video Auto Play
  36. define('BX_TIMELINE_VAP_OFF', 'off');
  37. define('BX_TIMELINE_VAP_ON_MUTE', 'on_mute');
  38. define('BX_TIMELINE_VAP_ON', 'on');
  39. class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolContentInfoService
  40. {
  41. protected $_sJsPostObject;
  42. protected $_sJsViewObject;
  43. protected $_aPostElements;
  44. protected $_sJsOutlineObject;
  45. protected $_sDividerTemplate;
  46. protected $_sBalloonTemplate;
  47. protected $_sCmtPostTemplate;
  48. protected $_sCmtViewTemplate;
  49. protected $_sCmtTemplate;
  50. /**
  51. * Constructor
  52. */
  53. function __construct($aModule)
  54. {
  55. parent::__construct($aModule);
  56. }
  57. /**
  58. * ACTION METHODS
  59. */
  60. public function actionVideo($iEventId, $iVideoId)
  61. {
  62. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iEventId));
  63. if(empty($aEvent) || !is_array($aEvent))
  64. return;
  65. $aData = $this->_oTemplate->getDataCached($aEvent);
  66. if($aData === false || !isset($aData['content']['videos'][$iVideoId]))
  67. return;
  68. $oTemplate = $this->_oTemplate;
  69. $oTemplate->setPageNameIndex (BX_PAGE_CLEAR);
  70. $oTemplate->setPageContent ('page_main_code', $this->_oTemplate->getVideo($aEvent, $aData['content']['videos'][$iVideoId]));
  71. $oTemplate->getPageCode();
  72. }
  73. public function actionPost()
  74. {
  75. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  76. $mixedAllowed = $this->isAllowedPost(true);
  77. if($mixedAllowed !== true)
  78. return echoJson(array('message' => strip_tags($mixedAllowed)));
  79. echoJson($this->getFormPost());
  80. }
  81. public function actionEdit($iId)
  82. {
  83. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  84. $aBrowseParams = array();
  85. if(bx_get('bp') !== false)
  86. $aBrowseParams = $this->_oConfig->getBrowseParams(bx_process_input(bx_get('bp')));
  87. $mixedAllowed = $this->isAllowedPost(true);
  88. if($mixedAllowed !== true)
  89. return echoJson(array('message' => strip_tags($mixedAllowed)));
  90. echoJson($this->getFormEdit($iId, array('dynamic_mode' => true), $aBrowseParams));
  91. }
  92. function actionPin()
  93. {
  94. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  95. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  96. if(empty($aEvent) || !is_array($aEvent))
  97. return echoJson(array('code' => 1));
  98. $aParams = $this->_prepareParamsGet();
  99. $this->_iOwnerId = $aParams['owner_id'];
  100. $mixedAllowed = $this->{'isAllowed' . ((int)$aEvent['pinned'] == 0 ? 'Pin' : 'Unpin')}($aEvent, true);
  101. if($mixedAllowed !== true)
  102. return echoJson(array('code' => 2, 'message' => strip_tags($mixedAllowed)));
  103. $aEvent['pinned'] = (int)$aEvent['pinned'] == 0 ? time() : 0;
  104. if(!$this->_oDb->updateEvent(array('pinned' => $aEvent['pinned']), array('id' => $iId)))
  105. return echoJson(array('code' => 3));
  106. echoJson(array(
  107. 'code' => 0,
  108. 'id' => $iId,
  109. 'eval' => $this->_oConfig->getJsObjectView($aParams) . '.onPinPost(oData)'
  110. ));
  111. }
  112. function actionStick()
  113. {
  114. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  115. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  116. if(empty($aEvent) || !is_array($aEvent))
  117. return echoJson(array('code' => 1));
  118. $aParams = $this->_prepareParamsGet();
  119. $this->_iOwnerId = $aParams['owner_id'];
  120. $mixedAllowed = $this->{'isAllowed' . ((int)$aEvent['sticked'] == 0 ? 'Stick' : 'Unstick')}($aEvent, true);
  121. if($mixedAllowed !== true)
  122. return echoJson(array('code' => 2, 'message' => strip_tags($mixedAllowed)));
  123. $aEvent['sticked'] = (int)$aEvent['sticked'] == 0 ? time() : 0;
  124. if(!$this->_oDb->updateEvent(array('sticked' => $aEvent['sticked']), array('id' => $iId)))
  125. return echoJson(array('code' => 3));
  126. echoJson(array(
  127. 'code' => 0,
  128. 'id' => $iId,
  129. 'eval' => $this->_oConfig->getJsObjectView($aParams) . '.onStickPost(oData)'
  130. ));
  131. }
  132. function actionPromote()
  133. {
  134. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  135. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  136. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  137. $sAction = (int)$aEvent['promoted'] == 0 ? 'promote' : 'unpromote';
  138. $mixedAllowed = $this->{'isAllowed' . ucfirst($sAction)}($aEvent, true);
  139. if($mixedAllowed !== true)
  140. return echoJson(array('code' => 1, 'message' => strip_tags($mixedAllowed)));
  141. $aEvent['promoted'] = (int)$aEvent['promoted'] == 0 ? time() : 0;
  142. if(!$this->_oDb->updateEvent(array('promoted' => $aEvent['promoted']), array('id' => $iId)))
  143. return echoJson(array('code' => 2));
  144. bx_alert($this->_oConfig->getObject('alert'), $sAction . 'd', $iId, (int)$this->getUserId(), array(
  145. 'owner_id' => $aEvent['owner_id'],
  146. 'object_id' => $aEvent['object_id'],
  147. 'object_author_id' => $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $aEvent['owner_id'] : $aEvent['object_id']
  148. ));
  149. echoJson(array(
  150. 'code' => 0,
  151. 'message' => _t('_bx_timeline_txt_msg_performed_action')
  152. ));
  153. }
  154. function actionDelete()
  155. {
  156. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  157. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  158. if(empty($aEvent) || !is_array($aEvent))
  159. return echoJson(array('code' => 1));
  160. $aParams = $this->_prepareParamsGet();
  161. $this->_iOwnerId = $aParams['owner_id'];
  162. $mixedAllowed = $this->isAllowedDelete($aEvent, true);
  163. if($mixedAllowed !== true)
  164. return echoJson(array('code' => 2, 'message' => strip_tags($mixedAllowed)));
  165. if(!$this->deleteEvent($aEvent))
  166. return echoJson(array('code' => 3));
  167. $this->_oDb->deleteCache(array('event_id' => $iId));
  168. echoJson(array(
  169. 'code' => 0,
  170. 'id' => $aEvent['id'],
  171. 'eval' => $this->_oConfig->getJsObjectView($aParams) . '.onDeletePost(oData)'
  172. ));
  173. }
  174. public function actionRepost()
  175. {
  176. $iAuthorId = $this->getUserId();
  177. $iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  178. $sType = bx_process_input(bx_get('type'), BX_DATA_TEXT);
  179. $sAction = bx_process_input(bx_get('action'), BX_DATA_TEXT);
  180. $iObjectId = bx_process_input(bx_get('object_id'), BX_DATA_INT);
  181. $aResult = $this->serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId);
  182. if(!empty($aResult) && is_array($aResult))
  183. return echoJson($aResult);
  184. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  185. $sCounter = $this->_oTemplate->getRepostCounter($aReposted);
  186. echoJson(array(
  187. 'code' => 0,
  188. 'message' => _t('_bx_timeline_txt_msg_success_repost'),
  189. 'count' => $aReposted['reposts'],
  190. 'countf' => (int)$aReposted['reposts'] > 0 ? $this->_oTemplate->getRepostCounterLabel($aReposted['reposts']) : '',
  191. 'counter' => $sCounter,
  192. 'disabled' => true
  193. ));
  194. }
  195. function actionGetPost()
  196. {
  197. $aParams = $this->_prepareParamsGet();
  198. $aParams['dynamic_mode'] = true;
  199. $this->_iOwnerId = $aParams['owner_id'];
  200. $sJsObject = '';
  201. if(bx_get('js_object') !== false)
  202. $sJsObject = bx_process_input(bx_get('js_object'));
  203. if(empty($sJsObject))
  204. $sJsObject = $this->_oConfig->getJsObject('post');
  205. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => bx_process_input(bx_get('id'), BX_DATA_INT)));
  206. if(empty($aEvent) || !is_array($aEvent))
  207. return echoJson(array());
  208. /**
  209. * Note. Disabled for now, because Own posts on Timelines of Following members
  210. * became visible on posts' author Dashboard Timeline.
  211. */
  212. /*
  213. $bAfpsLoading = (int)bx_get('afps_loading') === 1;
  214. if($bAfpsLoading && $this->_iOwnerId != $aEvent['owner_id'])
  215. return echoJson(array('message' => _t('_bx_timeline_txt_msg_posted')));
  216. */
  217. echoJson(array(
  218. 'id' => $aEvent['id'],
  219. 'name' => $aParams['name'],
  220. 'view' => $aParams['view'],
  221. 'type' => $aParams['type'],
  222. 'item' => $this->_oTemplate->getPost($aEvent, $aParams),
  223. 'eval' => $sJsObject . "._onGetPost(oData)"
  224. ));
  225. }
  226. function actionGetPosts()
  227. {
  228. $aParams = $this->_prepareParamsGet();
  229. list($sItems, $sLoadMore, $sBack, $sEmpty) = $this->_oTemplate->getPosts($aParams);
  230. echoJson(array(
  231. 'view' => $aParams['view'],
  232. 'items' => $sItems,
  233. 'load_more' => $sLoadMore,
  234. 'back' => $sBack,
  235. 'empty' => $sEmpty,
  236. 'eval' => $this->_oConfig->getJsObjectView($aParams) . "._onGetPosts(oData)"
  237. ));
  238. }
  239. public function actionGetPostForm()
  240. {
  241. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  242. $sType = bx_process_input(bx_get('type'));
  243. echoJson($this->getFormPost(array(
  244. 'type' => $sType,
  245. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  246. )));
  247. }
  248. public function actionGetEditForm($iId)
  249. {
  250. $aParams = $this->_prepareParamsGet();
  251. $this->_iOwnerId = $aParams['owner_id'];
  252. echoJson($this->getFormEdit($iId, array('dynamic_mode' => true), $aParams));
  253. }
  254. public function actionGetComments()
  255. {
  256. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  257. $sSystem = bx_process_input(bx_get('system'), BX_DATA_TEXT);
  258. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  259. $sComments = $this->_oTemplate->getComments($sSystem, $iId, array('dynamic_mode' => true));
  260. echoJson(array('content' => $sComments));
  261. }
  262. public function actionAddAttachLink()
  263. {
  264. $sUrl = bx_process_input(bx_get('url'));
  265. if(empty($sUrl))
  266. return echoJson(array());
  267. echoJson($this->addAttachLink(array(
  268. 'url' => $sUrl
  269. )));
  270. }
  271. public function actionDeleteAttachLink()
  272. {
  273. $iUserId = $this->getUserId();
  274. $iLinkId = bx_process_input(bx_get('id'), BX_DATA_INT);
  275. if(empty($iLinkId)) {
  276. echoJson(array());
  277. return;
  278. }
  279. $aLink = $this->_oDb->getUnusedLinks($iUserId, $iLinkId);
  280. if(empty($aLink) || !is_array($aLink)) {
  281. echoJson(array());
  282. return;
  283. }
  284. if(!empty($aLink['media_id']))
  285. BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'))->deleteFile($aLink['media_id']);
  286. $aResult = array();
  287. if($this->_oDb->deleteUnusedLinks($iUserId, $iLinkId))
  288. $aResult = array('code' => 0);
  289. else
  290. $aResult = array('code' => 1, 'message' => _t('_bx_timeline_form_post_input_link_err_delete'));
  291. echoJson($aResult);
  292. }
  293. public function actionGetAttachLinkForm()
  294. {
  295. echo $this->_oTemplate->getAttachLinkForm();
  296. }
  297. public function actionSubmitAttachLinkForm()
  298. {
  299. echoJson($this->getFormAttachLink());
  300. }
  301. public function actionGetRepostedBy()
  302. {
  303. $iRepostedId = bx_process_input(bx_get('id'), BX_DATA_INT);
  304. echo $this->_oTemplate->getRepostedBy($iRepostedId);
  305. }
  306. public function actionGetItemBrief()
  307. {
  308. echo BxDolPage::getObjectInstance($this->_oConfig->getObject('page_item_brief'), $this->_oTemplate)->getCode();
  309. }
  310. public function actionResumeLiveUpdate()
  311. {
  312. $aParams = $this->_prepareParamsGet();
  313. $sKey = $this->_oConfig->getLiveUpdateKey($aParams);
  314. bx_import('BxDolSession');
  315. BxDolSession::getInstance()->unsetValue($sKey);
  316. }
  317. public function actionPauseLiveUpdate()
  318. {
  319. $aParams = $this->_prepareParamsGet();
  320. $sKey = $this->_oConfig->getLiveUpdateKey($aParams);
  321. bx_import('BxDolSession');
  322. BxDolSession::getInstance()->setValue($sKey, 1);
  323. }
  324. function actionRss()
  325. {
  326. $CNF = &$this->_oConfig->CNF;
  327. $aArgs = func_get_args();
  328. $sType = array_shift($aArgs);
  329. $iOwnerId = 0;
  330. switch($sType) {
  331. case BX_BASE_MOD_NTFS_TYPE_OWNER:
  332. $iOwnerId = array_shift($aArgs);
  333. list($sUserName) = $this->getUserInfo($iOwnerId);
  334. $sRssCaption = _t('_bx_timeline_txt_rss_caption', $sUserName);
  335. $sRssLink = $this->_oConfig->getViewUrl($iOwnerId);
  336. break;
  337. case BX_BASE_MOD_NTFS_TYPE_PUBLIC:
  338. $sRssCaption = _t('_bx_timeline_page_title_view_home');
  339. $sRssLink = $this->_oConfig->getHomeViewUrl();
  340. break;
  341. }
  342. $aParams = $this->_prepareParams(array(
  343. 'view' => BX_TIMELINE_VIEW_DEFAULT,
  344. 'type' => $sType,
  345. 'owner_id' => $iOwnerId,
  346. 'start' => 0,
  347. 'per_page' => $this->_oConfig->getRssLength(),
  348. 'timeline' => 0,
  349. 'filter' => '',
  350. 'modules' => array()
  351. ));
  352. $aEvents = $this->_oDb->getEvents($aParams);
  353. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->getObject('privacy_view'));
  354. $aRssData = array();
  355. foreach($aEvents as $aEvent) {
  356. if(empty($aEvent['title']))
  357. continue;
  358. $iEventId = (int)$aEvent[$CNF['FIELD_ID']];
  359. $sEventFieldAuthor = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? 'owner_id' : 'object_id';
  360. if($oPrivacy) {
  361. $oPrivacy->setTableFieldAuthor($sEventFieldAuthor);
  362. if(!$oPrivacy->check($iEventId))
  363. continue;
  364. }
  365. $iOwner = $aEvent[$sEventFieldAuthor];
  366. $oOwner = BxDolProfile::getInstanceMagic($iOwner);
  367. $aRssData[$iEventId] = array(
  368. 'UnitID' => $iEventId,
  369. 'UnitTitle' => $aEvent['title'],
  370. 'UnitLink' => $this->_oConfig->getItemViewUrl($aEvent),
  371. 'UnitDesc' => bx_replace_markers($aEvent['description'], array(
  372. 'profile_name' => $oOwner->getDisplayName()
  373. )),
  374. 'UnitDateTimeUTS' => $aEvent['date'],
  375. );
  376. }
  377. $oRss = new BxDolRssFactory();
  378. header('Content-Type: application/xml; charset=utf-8');
  379. echo $oRss->GenRssByData($aRssData, $sRssCaption, $sRssLink);
  380. }
  381. /**
  382. * SERVICE METHODS
  383. */
  384. /**
  385. * @page service Service Calls
  386. * @section bx_timeline Timeline
  387. * @subsection bx_timeline-other Other
  388. * @subsubsection bx_timeline-get_create_post_form get_create_post_form
  389. *
  390. * @code bx_srv('bx_timeline', 'get_create_post_form', [...]); @endcode
  391. *
  392. * Get form code for add content. Is needed for United Post Form.
  393. *
  394. * @param $aParams optional array with parameters(display name, etc)
  395. * @return form code or error
  396. *
  397. * @see BxTimelineModule::serviceGetCreatePostForm
  398. */
  399. /**
  400. * @ref bx_timeline-get_create_post_form "get_create_post_form"
  401. */
  402. public function serviceGetCreatePostForm($aParams = array())
  403. {
  404. $aParams = array_merge($this->_aFormParams, $aParams);
  405. $this->_iOwnerId = $aParams['context_id'];
  406. $oForm = $this->serviceGetObjectForm('add', $aParams);
  407. if(!$oForm)
  408. return '';
  409. if(!empty($aParams['display']))
  410. $aParams['form_display'] = $aParams['display'];
  411. else if(isset($aParams['context_id'])) {
  412. if((int)$aParams['context_id'] == 0)
  413. $aParams['form_display'] = 'form_display_post_add_public';
  414. else
  415. $aParams['form_display'] = 'form_display_post_add_profile';
  416. }
  417. $aResult = $this->getFormPost($aParams);
  418. if(!empty($aResult['form'])) {
  419. $bDynamicMode = isset($aParams['dynamic_mode']) && $aParams['dynamic_mode'];
  420. $sCode = '';
  421. $sCode .= $this->_oTemplate->getCssJs($bDynamicMode);
  422. $sCode .= $this->_oTemplate->getJsCodePost($this->_iOwnerId);
  423. $sCode .= $aResult['form'];
  424. return $sCode;
  425. }
  426. if(!empty($aResult['message']))
  427. return $aResult['message'];
  428. return '';
  429. }
  430. /**
  431. * @page service Service Calls
  432. * @section bx_timeline Timeline
  433. * @subsection bx_timeline-other Other
  434. * @subsubsection bx_timeline-get_object_form get_object_form
  435. *
  436. * @code bx_srv('bx_timeline', 'get_object_form', [...]); @endcode
  437. *
  438. * Get form object for add, edit, view or delete the content.
  439. *
  440. * @param $sType 'add' is supported only
  441. * @param $aParams optional array with parameters(display name, etc)
  442. * @return form object or false on error
  443. *
  444. * @see BxTimelineModule::serviceGetObjectForm
  445. */
  446. /**
  447. * @ref bx_timeline-get_object_form "get_object_form"
  448. */
  449. public function serviceGetObjectForm ($sType, $aParams = array())
  450. {
  451. if (!in_array($sType, array('add')))
  452. return false;
  453. $CNF = &$this->_oConfig->CNF;
  454. if(!empty($aParams['display']))
  455. $aParams['form_display'] = $aParams['display'];
  456. else if(isset($aParams['context_id'])) {
  457. if((int)$aParams['context_id'] == 0)
  458. $aParams['form_display'] = 'form_display_post_add_public';
  459. else
  460. $aParams['form_display'] = 'form_display_post_add_profile';
  461. }
  462. $oForm = $this->getFormPostObject($aParams);
  463. bx_alert('system', 'get_object_form', 0, 0, array(
  464. 'module' => $this->_oConfig->getName(),
  465. 'type' => $sType,
  466. 'params' => $aParams,
  467. 'form' => &$oForm
  468. ));
  469. return $oForm;
  470. }
  471. /**
  472. * @page service Service Calls
  473. * @section bx_timeline Timeline
  474. * @subsection get_timeline_post
  475. * @see BxTimelineModule::serviceGetTimelinePost
  476. *
  477. * Get Timeline post. It's needed for Timeline module.
  478. *
  479. * @param $aEvent timeline event array from Timeline module
  480. * @return array in special format which is needed specifically for Timeline module to display the data.
  481. */
  482. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  483. {
  484. $CNF = &$this->_oConfig->CNF;
  485. /*
  486. * Note. For 'Direct Timeline Posts' FIELD_OBJECT_ID contains post's author profile ID.
  487. */
  488. $CNF['FIELD_AUTHOR'] = $CNF['FIELD_OBJECT_ID'];
  489. return parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  490. }
  491. /**
  492. * @page service Service Calls
  493. * @section bx_timeline Timeline
  494. * @subsection bx_timeline-other Other
  495. * @subsubsection bx_timeline-get_author get_author
  496. *
  497. * @code bx_srv('bx_timeline', 'get_author', [...]); @endcode
  498. *
  499. * Get author ID from content info by content ID. Is used in "Content Info Objects" system.
  500. *
  501. * @param $iContentId integer value with content ID.
  502. * @return integer value with author ID.
  503. *
  504. * @see BxTimelineModule::serviceGetAuthor
  505. */
  506. /**
  507. * @ref bx_timeline-get_author "get_author"
  508. */
  509. public function serviceGetAuthor ($iContentId)
  510. {
  511. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  512. if(empty($aEvent) || !is_array($aEvent))
  513. return 0;
  514. return $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? (int)$aEvent['owner_id'] : (int)$aEvent['object_id'];
  515. }
  516. /**
  517. * @page service Service Calls
  518. * @section bx_timeline Timeline
  519. * @subsection bx_timeline-other Other
  520. * @subsubsection bx_timeline-get_date_changed get_date_changed
  521. *
  522. * @code bx_srv('bx_timeline', 'get_date_changed', [...]); @endcode
  523. *
  524. * Get date when the content was changed last time. Is used in "Content Info Objects" system.
  525. * Note. In case of Timeline event 0 is returned everytime.
  526. *
  527. * @param $iContentId integer value with content ID.
  528. * @return integer value with changing date.
  529. *
  530. * @see BxTimelineModule::serviceGetDateChanged
  531. */
  532. /**
  533. * @ref bx_timeline-get_date_changed "get_date_changed"
  534. */
  535. public function serviceGetDateChanged ($iContentId)
  536. {
  537. return 0;
  538. }
  539. /**
  540. * @page service Service Calls
  541. * @section bx_timeline Timeline
  542. * @subsection bx_timeline-other Other
  543. * @subsubsection bx_timeline-get_link get_link
  544. *
  545. * @code bx_srv('bx_timeline', 'get_link', [...]); @endcode
  546. *
  547. * Get content view page link. Is used in "Content Info Objects" system.
  548. *
  549. * @param $iContentId integer value with content ID.
  550. * @return string value with view page link.
  551. *
  552. * @see BxTimelineModule::serviceGetLink
  553. */
  554. /**
  555. * @ref bx_timeline-get_link "get_link"
  556. */
  557. public function serviceGetLink ($iContentId)
  558. {
  559. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  560. if(empty($aEvent) || !is_array($aEvent))
  561. return '';
  562. return $this->_oConfig->getItemViewUrl($aEvent);
  563. }
  564. /**
  565. * @page service Service Calls
  566. * @section bx_timeline Timeline
  567. * @subsection bx_timeline-other Other
  568. * @subsubsection bx_timeline-get_thumb get_thumb
  569. *
  570. * @code bx_srv('bx_timeline', 'get_thumb', [...]); @endcode
  571. *
  572. * Get content thumbnail link. Is used in "Content Info Objects" system.
  573. * Note. In case of Timeline event an empty string is returned everytime.
  574. *
  575. * @param $iContentId integer value with content ID.
  576. * @param $sTranscoder (optional) string value with transcoder name which should be applied to thumbnail image.
  577. * @return string value with thumbnail link.
  578. *
  579. * @see BxTimelineModule::serviceGetThumb
  580. */
  581. /**
  582. * @ref bx_timeline-get_thumb "get_thumb"
  583. */
  584. public function serviceGetThumb ($iContentId, $sTranscoder = '')
  585. {
  586. return '';
  587. }
  588. /**
  589. * @page service Service Calls
  590. * @section bx_timeline Timeline
  591. * @subsection bx_timeline-other Other
  592. * @subsubsection bx_timeline-get_info get_info
  593. *
  594. * @code bx_srv('bx_timeline', 'get_info', [...]); @endcode
  595. *
  596. * Get content info by content ID. Is used in "Content Info Objects" system.
  597. *
  598. * @param $iContentId integer value with content ID.
  599. * @param $bSearchableFieldsOnly (optional) boolean value determining all info or "searchable fields" only will be returned.
  600. * @return an array with content info. Empty array is returned if something is wrong.
  601. *
  602. * @see BxTimelineModule::serviceGetInfo
  603. */
  604. /**
  605. * @ref bx_timeline-get_info "get_info"
  606. */
  607. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  608. {
  609. $aContentInfo = $this->_oDb->getEvents(array(
  610. 'browse' => 'id',
  611. 'value' => $iContentId)
  612. );
  613. return BxDolContentInfo::formatFields($aContentInfo);
  614. }
  615. /**
  616. * @page service Service Calls
  617. * @section bx_timeline Timeline
  618. * @subsection bx_timeline-other Other
  619. * @subsubsection bx_timeline-get_search_result_unit get_search_result_unit
  620. *
  621. * @code bx_srv('bx_timeline', 'get_search_result_unit', [...]); @endcode
  622. *
  623. * Get search result unit by content ID. Is used in "Content Info Objects" system.
  624. *
  625. * @param $iContentId integer value with content ID.
  626. * @param $sUnitTemplate (optional) string value with template name.
  627. * @return HTML string with search result unit. Empty string is returned if something is wrong.
  628. *
  629. * @see BxTimelineModule::serviceGetSearchResultUnit
  630. */
  631. /**
  632. * @ref bx_timeline-get_search_result_unit "get_search_result_unit"
  633. */
  634. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  635. {
  636. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  637. if(empty($aEvent) || !is_array($aEvent))
  638. return '';
  639. if(empty($sUnitTemplate))
  640. $sUnitTemplate = 'unit.html';
  641. return $this->_oTemplate->unit($aEvent, true, $sUnitTemplate);
  642. }
  643. /**
  644. * @page service Service Calls
  645. * @section bx_timeline Timeline
  646. * @subsection bx_timeline-page_blocks Page Blocks
  647. * @subsubsection bx_timeline-get_block_post get_block_post
  648. *
  649. * @code bx_srv('bx_timeline', 'get_block_post', [...]); @endcode
  650. *
  651. * Get Post block for a separate page.
  652. *
  653. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  654. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  655. *
  656. * @see BxTimelineModule::serviceGetBlockPost
  657. */
  658. /**
  659. * @ref bx_timeline-get_block_post "get_block_post"
  660. */
  661. public function serviceGetBlockPost($iProfileId = 0)
  662. {
  663. if(empty($iProfileId) && bx_get('profile_id') !== false)
  664. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  665. if(empty($iProfileId) && isLogged())
  666. $iProfileId = bx_get_logged_profile_id();
  667. if(!$iProfileId)
  668. return array();
  669. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  670. return $this->_getBlockPost($iProfileId, array(
  671. 'type' => $sType,
  672. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  673. ));
  674. }
  675. /**
  676. * @page service Service Calls
  677. * @section bx_timeline Timeline
  678. * @subsection bx_timeline-page_blocks Page Blocks
  679. * @subsubsection bx_timeline-get_block_post_profile get_block_post_profile
  680. *
  681. * @code bx_srv('bx_timeline', 'get_block_post_profile', [...]); @endcode
  682. *
  683. * Get Post block for the Profile page.
  684. *
  685. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  686. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  687. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  688. *
  689. * @see BxTimelineModule::serviceGetBlockPostProfile
  690. */
  691. /**
  692. * @ref bx_timeline-get_block_post_profile "get_block_post_profile"
  693. */
  694. public function serviceGetBlockPostProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0)
  695. {
  696. if(empty($sProfileModule))
  697. return array();
  698. if(empty($iProfileContentId) && bx_get('id') !== false)
  699. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  700. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  701. if(empty($oProfile))
  702. return array();
  703. $iProfileId = $oProfile->id();
  704. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  705. return $this->_getBlockPost($iProfileId, array(
  706. 'type' => $sType,
  707. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  708. ));
  709. }
  710. /**
  711. * @page service Service Calls
  712. * @section bx_timeline Timeline
  713. * @subsection bx_timeline-page_blocks Page Blocks
  714. * @subsubsection bx_timeline-get_block_post_home get_block_post_home
  715. *
  716. * @code bx_srv('bx_timeline', 'get_block_post_home', [...]); @endcode
  717. *
  718. * Get Post block for site's Home page.
  719. *
  720. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  721. *
  722. * @see BxTimelineModule::serviceGetBlockPostHome
  723. */
  724. /**
  725. * @ref bx_timeline-get_block_post_home "get_block_post_home"
  726. */
  727. public function serviceGetBlockPostHome()
  728. {
  729. $iProfileId = 0;
  730. $sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  731. return $this->_getBlockPost($iProfileId, array(
  732. 'type' => $sType,
  733. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  734. ));
  735. }
  736. /**
  737. * @page service Service Calls
  738. * @section bx_timeline Timeline
  739. * @subsection bx_timeline-page_blocks Page Blocks
  740. * @subsubsection bx_timeline-get_block_post_account get_block_post_account
  741. *
  742. * @code bx_srv('bx_timeline', 'get_block_post_account', [...]); @endcode
  743. *
  744. * Get Post block for the Dashboard page.
  745. *
  746. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  747. *
  748. * @see BxTimelineModule::serviceGetBlockPostAccount
  749. */
  750. /**
  751. * @ref bx_timeline-get_block_post_account "get_block_post_account"
  752. */
  753. public function serviceGetBlockPostAccount()
  754. {
  755. if(!isLogged())
  756. return '';
  757. $iProfileId = $this->getProfileId();
  758. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  759. return $this->_getBlockPost($iProfileId, array(
  760. 'type' => $sType,
  761. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  762. ));
  763. }
  764. /**
  765. * @page service Service Calls
  766. * @section bx_timeline Timeline
  767. * @subsection bx_timeline-page_blocks Page Blocks
  768. * @subsubsection bx_timeline-get_block_view get_block_view
  769. *
  770. * @code bx_srv('bx_timeline', 'get_block_view', [...]); @endcode
  771. *
  772. * Get Timeline View block for a separate page.
  773. *
  774. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  775. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  776. *
  777. * @see BxTimelineModule::serviceGetBlockView
  778. */
  779. /**
  780. * @ref bx_timeline-get_block_view "get_block_view"
  781. */
  782. public function serviceGetBlockView($iProfileId = 0)
  783. {
  784. return $this->_serviceGetBlockView($iProfileId, array(
  785. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  786. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  787. 'start' => -1,
  788. 'per_page' => -1,
  789. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  790. 'timeline' => -1,
  791. 'filter' => '',
  792. 'modules' => array()
  793. ));
  794. }
  795. /**
  796. * @page service Service Calls
  797. * @section bx_timeline Timeline
  798. * @subsection bx_timeline-page_blocks Page Blocks
  799. * @subsubsection bx_timeline-get_block_view_outline get_block_view_outline
  800. *
  801. * @code bx_srv('bx_timeline', 'get_block_view_outline', [...]); @endcode
  802. *
  803. * Get Outline View block for a separate page.
  804. *
  805. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  806. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  807. *
  808. * @see BxTimelineModule::serviceGetBlockViewOutline
  809. */
  810. /**
  811. * @ref bx_timeline-get_block_view_outline "get_block_view_outline"
  812. */
  813. public function serviceGetBlockViewOutline($iProfileId = 0)
  814. {
  815. return $this->_serviceGetBlockView($iProfileId, array(
  816. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  817. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  818. 'start' => -1,
  819. 'per_page' => -1,
  820. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  821. 'timeline' => -1,
  822. 'filter' => '',
  823. 'modules' => array()
  824. ));
  825. }
  826. /**
  827. * @page service Service Calls
  828. * @section bx_timeline Timeline
  829. * @subsection bx_timeline-page_blocks Page Blocks
  830. * @subsubsection bx_timeline-get_block_view_profile get_block_view_profile
  831. *
  832. * @code bx_srv('bx_timeline', 'get_block_view_profile', [...]); @endcode
  833. *
  834. * Get Timeline View block for the Profile page.
  835. *
  836. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  837. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  838. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  839. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  840. * @param $sFilter (optional) string value with filter name.
  841. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  842. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  843. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  844. *
  845. * @see BxTimelineModule::serviceGetBlockViewProfile
  846. */
  847. /**
  848. * @ref bx_timeline-get_block_view_profile "get_block_view_profile"
  849. */
  850. public function serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  851. {
  852. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, array(
  853. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  854. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  855. 'start' => $iStart,
  856. 'per_page' => $iPerPage,
  857. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  858. 'timeline' => $iTimeline,
  859. 'filter' => $sFilter,
  860. 'modules' => $aModules
  861. ));
  862. }
  863. /**
  864. * @page service Service Calls
  865. * @section bx_timeline Timeline
  866. * @subsection bx_timeline-page_blocks Page Blocks
  867. * @subsubsection bx_timeline-get_block_view_profile_outline get_block_view_profile_outline
  868. *
  869. * @code bx_srv('bx_timeline', 'get_block_view_profile_outline', [...]); @endcode
  870. *
  871. * Get Outline View block for the Profile page.
  872. *
  873. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  874. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  875. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  876. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  877. * @param $sFilter (optional) string value with filter name.
  878. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  879. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  880. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  881. *
  882. * @see BxTimelineModule::serviceGetBlockViewProfileOutline
  883. */
  884. /**
  885. * @ref bx_timeline-get_block_view_profile_outline "get_block_view_profile_outline"
  886. */
  887. public function serviceGetBlockViewProfileOutline($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  888. {
  889. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, array(
  890. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  891. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  892. 'start' => $iStart,
  893. 'per_page' => $iPerPage,
  894. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  895. 'timeline' => $iTimeline,
  896. 'filter' => $sFilter,
  897. 'modules' => $aModules
  898. ));
  899. }
  900. /**
  901. * @page service Service Calls
  902. * @section bx_timeline Timeline
  903. * @subsection bx_timeline-page_blocks Page Blocks
  904. * @subsubsection bx_timeline-get_block_view_home get_block_view_home
  905. *
  906. * @code bx_srv('bx_timeline', 'get_block_view_home', [...]); @endcode
  907. *
  908. * Get Timeline View block for site's Home page.
  909. *
  910. * @param $iProfileId (optional) profile ID. 0 should be used here.
  911. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  912. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  913. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  914. * @param $sFilter (optional) string value with filter name.
  915. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  916. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  917. *
  918. * @see BxTimelineModule::serviceGetBlockViewHome
  919. */
  920. /**
  921. * @ref bx_timeline-get_block_view_home "get_block_view_home"
  922. */
  923. public function serviceGetBlockViewHome($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  924. {
  925. return $this->_serviceGetBlockViewHome(array(
  926. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  927. 'type' => BX_BASE_MOD_NTFS_TYPE_PUBLIC,
  928. 'owner_id' => $iProfileId,
  929. 'start' => $iStart,
  930. 'per_page' => $iPerPage,
  931. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  932. 'timeline' => $iTimeline,
  933. 'filter' => $sFilter,
  934. 'modules' => $aModules
  935. ));
  936. }
  937. /**
  938. * @page service Service Calls
  939. * @section bx_timeline Timeline
  940. * @subsection bx_timeline-page_blocks Page Blocks
  941. * @subsubsection bx_timeline-get_block_view_home_outline get_block_view_home_outline
  942. *
  943. * @code bx_srv('bx_timeline', 'get_block_view_home_outline', [...]); @endcode
  944. *
  945. * Get Outline View block for site's Home page.
  946. *
  947. * @param $iProfileId (optional) profile ID. 0 should be used here.
  948. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  949. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  950. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  951. * @param $sFilter (optional) string value with filter name.
  952. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  953. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  954. *
  955. * @see BxTimelineModule::serviceGetBlockViewHomeOutline
  956. */
  957. /**
  958. * @ref bx_timeline-get_block_view_home_outline "get_block_view_home_outline"
  959. */
  960. public function serviceGetBlockViewHomeOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  961. {
  962. return $this->_serviceGetBlockViewHome(array(
  963. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  964. 'type' => BX_BASE_MOD_NTFS_TYPE_PUBLIC,
  965. 'owner_id' => $iProfileId,
  966. 'start' => $iStart,
  967. 'per_page' => $iPerPage,
  968. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  969. 'timeline' => $iTimeline,
  970. 'filter' => $sFilter,
  971. 'modules' => $aModules
  972. ));
  973. }
  974. /**
  975. * @page service Service Calls
  976. * @section bx_timeline Timeline
  977. * @subsection bx_timeline-page_blocks Page Blocks
  978. * @subsubsection bx_timeline-get_block_view_hot get_block_view_hot
  979. *
  980. * @code bx_srv('bx_timeline', 'get_block_view_hot', [...]); @endcode
  981. *
  982. * Get Timeline View block with Hot public events.
  983. *
  984. * @param $iProfileId (optional) profile ID. 0 should be used here.
  985. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  986. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  987. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  988. * @param $sFilter (optional) string value with filter name.
  989. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  990. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  991. *
  992. * @see BxTimelineModule::serviceGetBlockViewHot
  993. */
  994. /**
  995. * @ref bx_timeline-get_block_view_hot "get_block_view_hot"
  996. */
  997. public function serviceGetBlockViewHot($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  998. {
  999. return $this->_serviceGetBlockViewHot(array(
  1000. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1001. 'type' => BX_TIMELINE_TYPE_HOT,
  1002. 'owner_id' => $iProfileId,
  1003. 'start' => $iStart,
  1004. 'per_page' => $iPerPage,
  1005. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  1006. 'timeline' => $iTimeline,
  1007. 'filter' => $sFilter,
  1008. 'modules' => $aModules
  1009. ));
  1010. }
  1011. /**
  1012. * @page service Service Calls
  1013. * @section bx_timeline Timeline
  1014. * @subsection bx_timeline-page_blocks Page Blocks
  1015. * @subsubsection bx_timeline-get_block_view_hot_outline get_block_view_hot_outline
  1016. *
  1017. * @code bx_srv('bx_timeline', 'get_block_view_hot_outline', [...]); @endcode
  1018. *
  1019. * Get Outline View block with Hot public events.
  1020. *
  1021. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1022. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1023. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1024. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1025. * @param $sFilter (optional) string value with filter name.
  1026. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1027. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1028. *
  1029. * @see BxTimelineModule::serviceGetBlockViewHotOutline
  1030. */
  1031. /**
  1032. * @ref bx_timeline-get_block_view_hot_outline "get_block_view_hot_outline"
  1033. */
  1034. public function serviceGetBlockViewHotOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1035. {
  1036. return $this->_serviceGetBlockViewHot(array(
  1037. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1038. 'type' => BX_TIMELINE_TYPE_HOT,
  1039. 'owner_id' => $iProfileId,
  1040. 'start' => $iStart,
  1041. 'per_page' => $iPerPage,
  1042. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  1043. 'timeline' => $iTimeline,
  1044. 'filter' => $sFilter,
  1045. 'modules' => $aModules
  1046. ));
  1047. }
  1048. /**
  1049. * @page service Service Calls
  1050. * @section bx_timeline Timeline
  1051. * @subsection bx_timeline-page_blocks Page Blocks
  1052. * @subsubsection bx_timeline-get_block_view_account get_block_view_account
  1053. *
  1054. * @code bx_srv('bx_timeline', 'get_block_view_account', [...]); @endcode
  1055. *
  1056. * Get Timeline View block for the Dashboard page.
  1057. *
  1058. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1059. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1060. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1061. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1062. * @param $sFilter (optional) string value with filter name.
  1063. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1064. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1065. *
  1066. * @see BxTimelineModule::serviceGetBlockViewAccount
  1067. */
  1068. /**
  1069. * @ref bx_timeline-get_block_view_account "get_block_view_account"
  1070. */
  1071. public function serviceGetBlockViewAccount($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1072. {
  1073. if(!isLogged())
  1074. return '';
  1075. return $this->_serviceGetBlockViewByType(array(
  1076. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1077. 'type' => BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS,
  1078. 'owner_id' => $iProfileId,
  1079. 'start' => $iStart,
  1080. 'per_page' => $iPerPage,
  1081. 'per_page_default' => $this->_oConfig->getPerPage('account'),
  1082. 'timeline' => $iTimeline,
  1083. 'filter' => $sFilter,
  1084. 'modules' => $aModules
  1085. ));
  1086. }
  1087. /**
  1088. * @page service Service Calls
  1089. * @section bx_timeline Timeline
  1090. * @subsection bx_timeline-page_blocks Page Blocks
  1091. * @subsubsection bx_timeline-get_block_view_account_outline get_block_view_account_outline
  1092. *
  1093. * @code bx_srv('bx_timeline', 'get_block_view_account_outline', [...]); @endcode
  1094. *
  1095. * Get Outline View block for the Dashboard page.
  1096. *
  1097. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1098. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1099. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1100. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1101. * @param $sFilter (optional) string value with filter name.
  1102. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1103. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1104. *
  1105. * @see BxTimelineModule::serviceGetBlockViewAccountOutline
  1106. */
  1107. /**
  1108. * @ref bx_timeline-get_block_view_account_outline "get_block_view_account_outline"
  1109. */
  1110. public function serviceGetBlockViewAccountOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1111. {
  1112. if(!isLogged())
  1113. return '';
  1114. return $this->_serviceGetBlockViewByType(array(
  1115. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1116. 'type' => BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS,
  1117. 'owner_id' => $iProfileId,
  1118. 'start' => $iStart,
  1119. 'per_page' => $iPerPage,
  1120. 'per_page_default' => $this->_oConfig->getPerPage('account'),
  1121. 'timeline' => $iTimeline,
  1122. 'filter' => $sFilter,
  1123. 'modules' => $aModules
  1124. ));
  1125. }
  1126. /**
  1127. * @page service Service Calls
  1128. * @section bx_timeline Timeline
  1129. * @subsection bx_timeline-page_blocks Page Blocks
  1130. * @subsubsection bx_timeline-get_block_view_custom get_block_view_custom
  1131. *
  1132. * @code bx_srv('bx_timeline', 'get_block_view_custom', [...]); @endcode
  1133. *
  1134. * Get custom Timeline View block.
  1135. *
  1136. * @param $aParams (optional) an array with block parameneters.
  1137. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1138. *
  1139. * @see BxTimelineModule::serviceGetBlockViewCustom
  1140. */
  1141. /**
  1142. * @ref bx_timeline-get_block_view_custom "get_block_view_custom"
  1143. */
  1144. public function serviceGetBlockViewCustom($aParams = array())
  1145. {
  1146. return $this->_serviceGetBlockViewByType($aParams);
  1147. }
  1148. /**
  1149. * @page service Service Calls
  1150. * @section bx_timeline Timeline
  1151. * @subsection bx_timeline-page_blocks Page Blocks
  1152. * @subsubsection bx_timeline-get_block_item get_block_item
  1153. *
  1154. * @code bx_srv('bx_timeline', 'get_block_item', [...]); @endcode
  1155. *
  1156. * Get View Item block.
  1157. *
  1158. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1159. *
  1160. * @see BxTimelineModule::serviceGetBlockItem
  1161. */
  1162. /**
  1163. * @ref bx_timeline-get_block_item "get_block_item"
  1164. */
  1165. public function serviceGetBlockItem()
  1166. {
  1167. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1168. if(!$iItemId)
  1169. return array();
  1170. $aParams = array(
  1171. 'view' => BX_TIMELINE_VIEW_ITEM,
  1172. 'type' => BX_TIMELINE_TYPE_ITEM
  1173. );
  1174. $aParams = $this->_prepareParams($aParams);
  1175. return $this->_oTemplate->getItemBlock($iItemId, $aParams);
  1176. }
  1177. public function serviceGetBlockItemContent()
  1178. {
  1179. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1180. $sMode = bx_process_input(bx_get('mode'));
  1181. if(!$iItemId || !$sMode)
  1182. return '';
  1183. return $this->_oTemplate->getItemBlockContent($iItemId, $sMode);
  1184. }
  1185. public function serviceGetBlockItemInfo()
  1186. {
  1187. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1188. if(!$iItemId)
  1189. return '';
  1190. return $this->_oTemplate->getItemBlockInfo($iItemId);
  1191. }
  1192. public function serviceGetBlockItemComments()
  1193. {
  1194. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1195. if(!$iItemId)
  1196. return '';
  1197. return $this->_oTemplate->getItemBlockComments($iItemId);
  1198. }
  1199. /**
  1200. * @page service Service Calls
  1201. * @section bx_timeline Timeline
  1202. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1203. * @subsubsection bx_timeline-get_notifications_data get_notifications_data
  1204. *
  1205. * @code bx_srv('bx_timeline', 'get_notifications_data', [...]); @endcode
  1206. *
  1207. * Data for Notifications module.
  1208. *
  1209. * @return an array with special format.
  1210. *
  1211. * @see BxTimelineModule::serviceGetNotificationsData
  1212. */
  1213. /**
  1214. * @ref bx_timeline-get_notifications_data "get_notifications_data"
  1215. */
  1216. public function serviceGetNotificationsData()
  1217. {
  1218. $sModule = $this->_aModule['name'];
  1219. return array(
  1220. 'handlers' => array(
  1221. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'post_common', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module'),
  1222. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete'),
  1223. array('group' => $sModule . '_repost', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'repost', 'module_name' => $sModule, 'module_method' => 'get_notifications_repost', 'module_class' => 'Module'),
  1224. array('group' => $sModule . '_repost', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete_repost'),
  1225. array('group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment', 'module_class' => 'Module'),
  1226. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  1227. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'),
  1228. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  1229. array('group' => $sModule . '_score_up', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteUp', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_up', 'module_class' => 'Module'),
  1230. array('group' => $sModule . '_score_down', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteDown', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_down', 'module_class' => 'Module'),
  1231. ),
  1232. 'settings' => array(
  1233. array('group' => 'content', 'unit' => $sModule, 'action' => 'post_common', 'types' => array('personal', 'follow_member', 'follow_context')),
  1234. array('group' => 'content', 'unit' => $sModule, 'action' => 'repost', 'types' => array('follow_member', 'follow_context')),
  1235. array('group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => array('personal', 'follow_member', 'follow_context')),
  1236. array('group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1237. array('group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => array('personal', 'follow_member', 'follow_context')),
  1238. array('group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => array('personal', 'follow_member', 'follow_context'))
  1239. ),
  1240. 'alerts' => array(
  1241. array('unit' => $sModule, 'action' => 'post_common'),
  1242. array('unit' => $sModule, 'action' => 'delete'),
  1243. array('unit' => $sModule, 'action' => 'repost'),
  1244. array('unit' => $sModule, 'action' => 'delete_repost'),
  1245. array('unit' => $sModule, 'action' => 'commentPost'),
  1246. array('unit' => $sModule, 'action' => 'commentRemoved'),
  1247. array('unit' => $sModule, 'action' => 'doVote'),
  1248. array('unit' => $sModule, 'action' => 'undoVote'),
  1249. array('unit' => $sModule, 'action' => 'doVoteUp'),
  1250. array('unit' => $sModule, 'action' => 'doVoteDown'),
  1251. )
  1252. );
  1253. }
  1254. /**
  1255. * @page service Service Calls
  1256. * @section bx_timeline Timeline
  1257. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1258. * @subsubsection bx_timeline-get_notifications_repost get_notifications_repost
  1259. *
  1260. * @code bx_srv('bx_timeline', 'get_notifications_repost', [...]); @endcode
  1261. *
  1262. * Get data for Repost event to display in Notifications module.
  1263. *
  1264. * @param $aEvent an array with event description.
  1265. * @return an array with special format.
  1266. *
  1267. * @see BxTimelineModule::serviceGetNotificationsRepost
  1268. */
  1269. /**
  1270. * @ref bx_timeline-get_notifications_repost "get_notifications_repost"
  1271. */
  1272. public function serviceGetNotificationsRepost($aEvent)
  1273. {
  1274. $aResult = $this->serviceGetNotificationsPost($aEvent);
  1275. $aResult['lang_key'] = '_bx_timeline_txt_object_reposted';
  1276. return $aResult;
  1277. }
  1278. /**
  1279. * @page service Service Calls
  1280. * @section bx_timeline Timeline
  1281. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1282. * @subsubsection bx_timeline-get_notifications_post get_notifications_post
  1283. *
  1284. * @code bx_srv('bx_timeline', 'get_notifications_post', [...]); @endcode
  1285. *
  1286. * Get data for Post event to display in Notifications module.
  1287. *
  1288. * @param $aEvent an array with event description.
  1289. * @return an array with special format.
  1290. *
  1291. * @see BxTimelineModule::serviceGetNotificationsPost
  1292. */
  1293. /**
  1294. * @ref bx_timeline-get_notifications_post "get_notifications_post"
  1295. */
  1296. public function serviceGetNotificationsPost($aEvent)
  1297. {
  1298. $CNF = &$this->_oConfig->CNF;
  1299. $iContent = (int)$aEvent['object_id'];
  1300. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1301. if(empty($aContent) || !is_array($aContent))
  1302. return array();
  1303. if($this->_oConfig->isSystem($aContent['type'], $aContent['action']))
  1304. $iEntryAuthor = (int)$aContent['owner_id'];
  1305. else
  1306. $iEntryAuthor = (int)$aContent['object_id'];
  1307. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : $this->_oConfig->getTitle($aContent['description'], $aContent['object_id']);
  1308. return array(
  1309. 'entry_sample' => $CNF['T']['txt_sample_single_ext'],
  1310. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1311. 'entry_caption' => $sEntryCaption,
  1312. 'entry_author' => $iEntryAuthor,
  1313. 'lang_key' => '' //may be empty or not specified. In this case the default one from Notification module will be used.
  1314. );
  1315. }
  1316. /**
  1317. * @page service Service Calls
  1318. * @section bx_timeline Timeline
  1319. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1320. * @subsubsection bx_timeline-get_notifications_comment get_notifications_comment
  1321. *
  1322. * @code bx_srv('bx_timeline', 'get_notifications_comment', [...]); @endcode
  1323. *
  1324. * Get data for Post Comment event to display in Notifications module.
  1325. *
  1326. * @param $aEvent an array with event description.
  1327. * @return an array with special format.
  1328. *
  1329. * @see BxTimelineModule::serviceGetNotificationsComment
  1330. */
  1331. /**
  1332. * @ref bx_timeline-get_notifications_comment "get_notifications_comment"
  1333. */
  1334. public function serviceGetNotificationsComment($aEvent)
  1335. {
  1336. $CNF = &$this->_oConfig->CNF;
  1337. $iContent = (int)$aEvent['object_id'];
  1338. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1339. if(empty($aContent) || !is_array($aContent))
  1340. return array();
  1341. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContent);
  1342. if(!$oComment || !$oComment->isEnabled())
  1343. return array();
  1344. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : $this->_oConfig->getTitle($aContent['description'], $aContent['object_id']);
  1345. return array(
  1346. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1347. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1348. 'entry_caption' => $sEntryCaption,
  1349. 'entry_author' => $aContent['owner_id'],
  1350. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  1351. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  1352. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1353. );
  1354. }
  1355. /**
  1356. * @page service Service Calls
  1357. * @section bx_timeline Timeline
  1358. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1359. * @subsubsection bx_timeline-get_notifications_vote get_notifications_vote
  1360. *
  1361. * @code bx_srv('bx_timeline', 'get_notifications_vote', [...]); @endcode
  1362. *
  1363. * Get data for Vote event to display in Notifications module.
  1364. *
  1365. * @param $aEvent an array with event description.
  1366. * @return an array with special format.
  1367. *
  1368. * @see BxTimelineModule::serviceGetNotificationsVote
  1369. */
  1370. /**
  1371. * @ref bx_timeline-get_notifications_vote "get_notifications_vote"
  1372. */
  1373. public function serviceGetNotificationsVote($aEvent)
  1374. {
  1375. $CNF = &$this->_oConfig->CNF;
  1376. $iContent = (int)$aEvent['object_id'];
  1377. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1378. if(empty($aContent) || !is_array($aContent))
  1379. return array();
  1380. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContent);
  1381. if(!$oVote || !$oVote->isEnabled())
  1382. return array();
  1383. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : $this->_oConfig->getTitle($aContent['description'], $aContent['object_id']);
  1384. return array(
  1385. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1386. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1387. 'entry_caption' => $sEntryCaption,
  1388. 'entry_author' => $aContent['owner_id'],
  1389. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  1390. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1391. );
  1392. }
  1393. /**
  1394. * @page service Service Calls
  1395. * @section bx_timeline Timeline
  1396. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1397. * @subsubsection bx_timeline-get_notifications_score_up get_notifications_score_up
  1398. *
  1399. * @code bx_srv('bx_timeline', 'get_notifications_score_up', [...]); @endcode
  1400. *
  1401. * Get data for Score Up Vote event to display in Notifications module.
  1402. *
  1403. * @param $aEvent an array with event description.
  1404. * @return an array with special format.
  1405. *
  1406. * @see BxTimelineModule::serviceGetNotificationsScoreUp
  1407. */
  1408. /**
  1409. * @ref bx_timeline-get_notifications_score_up "get_notifications_score_up"
  1410. */
  1411. public function serviceGetNotificationsScoreUp($aEvent)
  1412. {
  1413. return $this->_serviceGetNotificationsScore('up', $aEvent);
  1414. }
  1415. /**
  1416. * @page service Service Calls
  1417. * @section bx_timeline Timeline
  1418. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1419. * @subsubsection bx_timeline-get_notifications_score_down get_notifications_score_down
  1420. *
  1421. * @code bx_srv('bx_timeline', 'get_notifications_score_down', [...]); @endcode
  1422. *
  1423. * Get data for Score Down Vote event to display in Notifications module.
  1424. *
  1425. * @param $aEvent an array with event description.
  1426. * @return an array with special format.
  1427. *
  1428. * @see BxTimelineModule::serviceGetNotificationsScoreDown
  1429. */
  1430. /**
  1431. * @ref bx_timeline-get_notifications_score_down "get_notifications_score_down"
  1432. */
  1433. public function serviceGetNotificationsScoreDown($aEvent)
  1434. {
  1435. return $this->_serviceGetNotificationsScore('down', $aEvent);
  1436. }
  1437. protected function _serviceGetNotificationsScore($sType, $aEvent)
  1438. {
  1439. $CNF = &$this->_oConfig->CNF;
  1440. $iContent = (int)$aEvent['object_id'];
  1441. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1442. if(empty($aContent) || !is_array($aContent))
  1443. return array();
  1444. $oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContent);
  1445. if(!$oScore || !$oScore->isEnabled())
  1446. return array();
  1447. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : $this->_oConfig->getTitle($aContent['description'], $aContent['object_id']);
  1448. return array(
  1449. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1450. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1451. 'entry_caption' => $sEntryCaption,
  1452. 'entry_author' => $aContent['owner_id'],
  1453. 'subentry_sample' => $CNF['T']['txt_sample_score_' . $sType . '_single'],
  1454. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1455. );
  1456. }
  1457. /**
  1458. * @page service Service Calls
  1459. * @section bx_timeline Timeline
  1460. * @subsection bx_timeline-repost Repost
  1461. * @subsubsection bx_timeline-get_repost_element_block get_repost_element_block
  1462. *
  1463. * @code bx_srv('bx_timeline', 'get_repost_element_block', [...]); @endcode
  1464. *
  1465. * Get repost element for content based modules.
  1466. *
  1467. * @param $iOwnerId integer value with owner profile ID.
  1468. * @param $sType string value with type (module name).
  1469. * @param $sAction string value with action (module action).
  1470. * @param $iObjectId integer value with object ID to be reposted.
  1471. * @param $aParams (optional) an array with additional params.
  1472. * @return HTML string with repost element to display on the site, all necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1473. *
  1474. * @see BxTimelineModule::serviceGetRepostElementBlock
  1475. */
  1476. /**
  1477. * @ref bx_timeline-get_repost_element_block "get_repost_element_block"
  1478. */
  1479. public function serviceGetRepostElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
  1480. {
  1481. if(!$this->isEnabled())
  1482. return '';
  1483. $aParams = array_merge($this->_oConfig->getRepostDefaults(), $aParams);
  1484. return $this->_oTemplate->getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
  1485. }
  1486. /**
  1487. * @page service Service Calls
  1488. * @section bx_timeline Timeline
  1489. * @subsection bx_timeline-repost Repost
  1490. * @subsubsection bx_timeline-get_repost_counter get_repost_counter
  1491. *
  1492. * @code bx_srv('bx_timeline', 'get_repost_counter', [...]); @endcode
  1493. *
  1494. * Get repost counter.
  1495. *
  1496. * @param $sType string value with type (module name).
  1497. * @param $sAction string value with action (module action).
  1498. * @param $iObjectId integer value with object ID to be reposted.
  1499. * @return HTML string with repost counter to display on the site, all necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1500. *
  1501. * @see BxTimelineModule::serviceGetRepostCounter
  1502. */
  1503. /**
  1504. * @ref bx_timeline-get_repost_counter "get_repost_counter"
  1505. */
  1506. public function serviceGetRepostCounter($sType, $sAction, $iObjectId)
  1507. {
  1508. if(!$this->isEnabled())
  1509. return '';
  1510. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1511. return $this->_oTemplate->getRepostCounter($aReposted);
  1512. }
  1513. /**
  1514. * @page service Service Calls
  1515. * @section bx_timeline Timeline
  1516. * @subsection bx_timeline-repost Repost
  1517. * @subsubsection bx_timeline-get_repost_js_script get_repost_js_script
  1518. *
  1519. * @code bx_srv('bx_timeline', 'get_repost_js_script', [...]); @endcode
  1520. *
  1521. * Get repost JavaScript code.
  1522. *
  1523. * @return HTML string with JavaScript code to display on the site, all necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1524. *
  1525. * @see BxTimelineModule::serviceGetRepostJsScript
  1526. */
  1527. /**
  1528. * @ref bx_timeline-get_repost_js_script "get_repost_js_script"
  1529. */
  1530. public function serviceGetRepostJsScript()
  1531. {
  1532. if(!$this->isEnabled())
  1533. return '';
  1534. return $this->_oTemplate->getRepostJsScript();
  1535. }
  1536. /**
  1537. * @page service Service Calls
  1538. * @section bx_timeline Timeline
  1539. * @subsection bx_timeline-repost Repost
  1540. * @subsubsection bx_timeline-get_repost_js_click get_repost_js_click
  1541. *
  1542. * @code bx_srv('bx_timeline', 'get_repost_js_click', [...]); @endcode
  1543. *
  1544. * Get repost JavaScript code for OnClick event.
  1545. *
  1546. * @param $iOwnerId integer value with owner profile ID.
  1547. * @param $sType string value with type (module name).
  1548. * @param $sAction string value with action (module action).
  1549. * @param $iObjectId integer value with object ID to be reposted.
  1550. * @return HTML string with JavaScript code to display in OnClick events of HTML elements.
  1551. *
  1552. * @see BxTimelineModule::serviceGetRepostJsClick
  1553. */
  1554. /**
  1555. * @ref bx_timeline-get_repost_js_click "get_repost_js_click"
  1556. */
  1557. public function serviceGetRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  1558. {
  1559. if(!$this->isEnabled())
  1560. return '';
  1561. return $this->_oTemplate->getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  1562. }
  1563. /**
  1564. * @page service Service Calls
  1565. * @section bx_timeline Timeline
  1566. * @subsection bx_timeline-repost Repost
  1567. * @subsubsection bx_timeline-repost repost
  1568. *
  1569. * @code bx_srv('bx_timeline', 'repost', [...]); @endcode
  1570. *
  1571. * Perform repost action.
  1572. *
  1573. * @param $iAuthorId integer value with performer profile ID.
  1574. * @param $iOwnerId integer value with repost event owner profile ID.
  1575. * @param $sType string value with type (module name).
  1576. * @param $sAction string value with action (module action).
  1577. * @param $iObjectId integer value with object ID to be reposted.
  1578. * @parem $bForce boolean value force reposting without ACL check.
  1579. * @return an array with error (code and message) or integer with newly created repost event ID.
  1580. *
  1581. * @see BxTimelineModule::serviceRepost
  1582. */
  1583. /**
  1584. * @ref bx_timeline-repost "repost"
  1585. */
  1586. public function serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $bForce = false)
  1587. {
  1588. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1589. if(empty($aReposted) || !is_array($aReposted))
  1590. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1591. $mixedAllowed = $this->isAllowedRepost($aReposted, true);
  1592. if(!$bForce && $mixedAllowed !== true)
  1593. return array('code' => 2, 'message' => strip_tags($mixedAllowed));
  1594. $bReposted = $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $iAuthorId);
  1595. if($bReposted)
  1596. return array('code' => 3, 'message' => _t('_bx_timeline_txt_err_already_reposted'));
  1597. $iId = $this->_oDb->insertEvent(array(
  1598. 'owner_id' => $iOwnerId,
  1599. 'type' => $this->_oConfig->getPrefix('common_post') . 'repost',
  1600. 'action' => '',
  1601. 'object_id' => $iAuthorId,
  1602. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault('object'),
  1603. 'content' => serialize(array(
  1604. 'type' => $sType,
  1605. 'action' => $sAction,
  1606. 'object_id' => $iObjectId,
  1607. )),
  1608. 'title' => '',
  1609. 'description' => ''
  1610. ));
  1611. if(empty($iId))
  1612. return array('code' => 4, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1613. $this->onRepost($iId, $aReposted);
  1614. return $iId;
  1615. }
  1616. /**
  1617. * @page service Service Calls
  1618. * @section bx_timeline Timeline
  1619. * @subsection bx_timeline-repost Repost
  1620. * @subsubsection bx_timeline-repost_by_id repost_by_id
  1621. *
  1622. * @code bx_srv('bx_timeline', 'repost_by_id', [...]); @endcode
  1623. *
  1624. * Perform repost action by Timeline event ID.
  1625. *
  1626. * @param $iAuthorId integer value with performer profile ID.
  1627. * @param $iOwnerId integer value with repost event owner profile ID.
  1628. * @param $iEventId integer value with event ID which will be reposted.
  1629. * @parem $bForce boolean value force reposting without ACL check.
  1630. * @return an array with error (code and message) or integer with newly created repost event ID.
  1631. *
  1632. * @see BxTimelineModule::serviceRepostById
  1633. */
  1634. /**
  1635. * @ref bx_timeline-repost_by_id "repost_by_id"
  1636. */
  1637. public function serviceRepostById($iAuthorId, $iOwnerId, $iEventId, $bForce = false)
  1638. {
  1639. $aEvent = $this->_oDb->getEntriesBy(array('type' => 'id', 'id' => $iEventId));
  1640. if(empty($aEvent) || !is_array($aEvent))
  1641. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1642. $sType = $aEvent['type'];
  1643. $sAction = $aEvent['action'];
  1644. $iObjectId = $this->_oConfig->isSystem($sType, $sAction) ? $aEvent['object_id'] : $aEvent['id'];
  1645. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  1646. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  1647. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1648. if(empty($aReposted) || !is_array($aReposted))
  1649. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1650. $aRepostedData = unserialize($aEvent['content']);
  1651. $sType = $aRepostedData['type'];
  1652. $sAction = $aRepostedData['action'];
  1653. $iObjectId = $aRepostedData['object_id'];
  1654. }
  1655. return $this->serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $bForce);
  1656. }
  1657. /**
  1658. * @page service Service Calls
  1659. * @section bx_timeline Timeline
  1660. * @subsection bx_timeline-other Other
  1661. * @subsubsection bx_timeline-update update
  1662. *
  1663. * @code bx_srv('bx_timeline', 'update', [...]); @endcode
  1664. *
  1665. * Update timeline event by ID.
  1666. *
  1667. * @param $iEventId integer value with event ID.
  1668. * @param $aSet an array with key=>value pairs for fields which should be updated.
  1669. * @return boolean value with the result of operation.
  1670. *
  1671. * @see BxTimelineModule::serviceUpdate
  1672. */
  1673. /**
  1674. * @ref bx_timeline-update "update"
  1675. */
  1676. public function serviceUpdate($iEventId, $aSet)
  1677. {
  1678. if(empty($iEventId))
  1679. return false;
  1680. return (int)$this->_oDb->updateEvent($aSet, array('id' => $iEventId)) > 0;
  1681. }
  1682. /**
  1683. * @page service Service Calls
  1684. * @section bx_timeline Timeline
  1685. * @subsection bx_timeline-other Other
  1686. * @subsubsection bx_timeline-get_menu_item_addon_comment get_menu_item_addon_comment
  1687. *
  1688. * @code bx_srv('bx_timeline', 'get_menu_item_addon_comment', [...]); @endcode
  1689. *
  1690. * Get addon for Comment menu item.
  1691. *
  1692. * @param $sSystem string value with comments engine system.
  1693. * @param $iObjectId integer value with object ID.
  1694. * @return HTML string to display in menu item.
  1695. *
  1696. * @see BxTimelineModule::serviceGetMenuItemAddonComment
  1697. */
  1698. /**
  1699. * @ref bx_timeline-get_menu_item_addon_comment "get_menu_item_addon_comment"
  1700. */
  1701. public function serviceGetMenuItemAddonComment($sSystem, $iObjectId, $aBrowseParams = array())
  1702. {
  1703. if(empty($sSystem) || empty($iObjectId))
  1704. return '';
  1705. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  1706. if($oCmts === false)
  1707. return '';
  1708. $iCounter = (int)$oCmts->getCommentsCount();
  1709. if(empty($iCounter))
  1710. return '';
  1711. return $this->_oTemplate->parseLink('javascript:void(0)', $iCounter, array(
  1712. 'class' => 'bx-menu-item-addon',
  1713. 'title' => _t('_bx_timeline_menu_item_title_item_comment'),
  1714. 'onclick' => "javascript:" . $this->_oConfig->getJsObjectView($aBrowseParams) . ".commentItem(this, '" . $sSystem . "', " . $iObjectId . ")"
  1715. ));
  1716. }
  1717. /**
  1718. * @page service Service Calls
  1719. * @section bx_timeline Timeline
  1720. * @subsection bx_timeline-other Other
  1721. * @subsubsection bx_timeline-get_settings_checker_helper get_settings_checker_helper
  1722. *
  1723. * @code bx_srv('bx_timeline', 'get_settings_checker_helper', [...]); @endcode
  1724. *
  1725. * Get Checker Helper class name for Forms engine.
  1726. *
  1727. * @return string with Checker Helper class name.
  1728. *
  1729. * @see BxTimelineModule::serviceGetSettingsCheckerHelper
  1730. */
  1731. /**
  1732. * @ref bx_timeline-get_settings_checker_helper "get_settings_checker_helper"
  1733. */
  1734. public function serviceGetSettingsCheckerHelper()
  1735. {
  1736. bx_import('FormCheckerHelper', $this->_aModule);
  1737. return 'BxTimelineFormCheckerHelper';
  1738. }
  1739. /**
  1740. * @page service Service Calls
  1741. * @section bx_timeline Timeline
  1742. * @subsection bx_timeline-other Other
  1743. * @subsubsection bx_timeline-get_options_videos_autoplay get_options_videos_autoplay
  1744. *
  1745. * @code bx_srv('bx_timeline', 'get_options_videos_autoplay', [...]); @endcode
  1746. *
  1747. * Get an array with available options for 'Videos autoplay in Timeline' setting.
  1748. *
  1749. * @return an array with available options represented as key => value pairs.
  1750. *
  1751. * @see BxTimelineModule::serviceGetOptionsVideosAutoplay
  1752. */
  1753. /**
  1754. * @ref bx_timeline-get_options_videos_autoplay "get_options_videos_autoplay"
  1755. */
  1756. public function serviceGetOptionsVideosAutoplay()
  1757. {
  1758. $aOptions = array(BX_TIMELINE_VAP_OFF, BX_TIMELINE_VAP_ON_MUTE, BX_TIMELINE_VAP_ON);
  1759. $aResult = array();
  1760. foreach($aOptions as $sOption)
  1761. $aResult[] = array(
  1762. 'key' => $sOption,
  1763. 'value' => _t('_bx_timeline_option_videos_autoplay_' . $sOption)
  1764. );
  1765. return $aResult;
  1766. }
  1767. /**
  1768. * @page service Service Calls
  1769. * @section bx_timeline Timeline
  1770. * @subsection bx_timeline-other Other
  1771. * @subsubsection bx_timeline-get_live_update get_live_update
  1772. *
  1773. * @code bx_srv('bx_timeline', 'get_live_update', [...]); @endcode
  1774. *
  1775. * Get an array with actual Live Update info. Only one live update notification for all new events.
  1776. *
  1777. * @return an array with Live Update info.
  1778. *
  1779. * @see BxTimelineModule::serviceGetLiveUpdate
  1780. */
  1781. /**
  1782. * @ref bx_timeline-get_live_update "get_live_update"
  1783. */
  1784. public function serviceGetLiveUpdate($aBrowseParams, $iProfileId, $iCount = 0, $iInit = 0)
  1785. {
  1786. $sKey = $this->_oConfig->getLiveUpdateKey($aBrowseParams);
  1787. bx_import('BxDolSession');
  1788. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  1789. return false;
  1790. $aParams = $this->_prepareParams($aBrowseParams);
  1791. $aParams['filter'] = BX_TIMELINE_FILTER_OTHER_VIEWER;
  1792. $aParams['count'] = true;
  1793. $iCountNew = $this->_oDb->getEvents($aParams);
  1794. if($iCountNew == $iCount)
  1795. return false;
  1796. if((int)$iInit != 0)
  1797. return array('count' => $iCountNew);
  1798. return array(
  1799. 'count' => $iCountNew, // required (for initialization and visualization)
  1800. 'method' => $this->_oConfig->getJsObjectView($aBrowseParams) . '.showLiveUpdate(oData)', // required (for visualization)
  1801. 'data' => array(
  1802. 'code' => $this->_oTemplate->getLiveUpdate($aBrowseParams, $iProfileId, $iCount, $iCountNew)
  1803. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  1804. );
  1805. }
  1806. /**
  1807. * @page service Service Calls
  1808. * @section bx_timeline Timeline
  1809. * @subsection bx_timeline-other Other
  1810. * @subsubsection bx_timeline-get_live_updates get_live_updates
  1811. *
  1812. * @code bx_srv('bx_timeline', 'get_live_updates', [...]); @endcode
  1813. *
  1814. * Get an array with actual Live Update info. Separate live update notification for each new Event.
  1815. *
  1816. * Note. This way to display live update notifications isn't used for now.
  1817. * See BxTimelineModule::serviceGetLiveUpdate method instead.
  1818. *
  1819. * @return an array with Live Update info.
  1820. *
  1821. * @see BxTimelineModule::serviceGetLiveUpdates
  1822. */
  1823. /**
  1824. * @ref bx_timeline-get_live_updates "get_live_updates"
  1825. */
  1826. public function serviceGetLiveUpdates($aBrowseParams, $iProfileId, $iCount = 0, $iInit = 0)
  1827. {
  1828. $sKey = $this->_oConfig->getLiveUpdateKey($aBrowseParams);
  1829. bx_import('BxDolSession');
  1830. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  1831. return false;
  1832. $aParams = $this->_prepareParams($aBrowseParams);
  1833. $aParams['filter'] = BX_TIMELINE_FILTER_OTHER_VIEWER;
  1834. $aParams['count'] = true;
  1835. $iCountNew = $this->_oDb->getEvents($aParams);
  1836. if($iCountNew == $iCount)
  1837. return false;
  1838. if((int)$iInit != 0)
  1839. return array('count' => $iCountNew);
  1840. return array(
  1841. 'count' => $iCountNew, // required (for initialization and visualization)
  1842. 'method' => $this->_oConfig->getJsObjectView($aBrowseParams) . '.showLiveUpdates(oData)', // required (for visualization)
  1843. 'data' => array(
  1844. 'code' => $this->_oTemplate->getLiveUpdates($aBrowseParams, $iProfileId, $iCount, $iCountNew)
  1845. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  1846. );
  1847. }
  1848. /**
  1849. * @page service Service Calls
  1850. * @section bx_timeline Accounts
  1851. * @subsection bx_timeline-other Other
  1852. * @subsubsection bx_timeline-get_menu_addon_manage_tools get_menu_addon_manage_tools
  1853. *
  1854. * @code bx_srv('bx_timeline', 'get_menu_addon_manage_tools', [...]); @endcode
  1855. *
  1856. * Get number of 'hidden' events for User End -> Dasboard page -> Manage block.
  1857. *
  1858. * @return integer number of 'hidden' events
  1859. *
  1860. * @see BxTimelineModule::serviceGetMenuAddonManageTools
  1861. */
  1862. /**
  1863. * @ref bx_timeline-get_menu_addon_manage_tools "get_menu_addon_manage_tools"
  1864. */
  1865. public function serviceGetMenuAddonManageTools()
  1866. {
  1867. bx_import('SearchResult', $this->_aModule);
  1868. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  1869. $oSearch = new $sClass();
  1870. $oSearch->fillFilters(array(
  1871. 'status' => BX_TIMELINE_STATUS_HIDDEN
  1872. ));
  1873. $oSearch->unsetPaginate();
  1874. return $oSearch->getNum();
  1875. }
  1876. /*
  1877. * COMMON METHODS
  1878. */
  1879. public function deleteEvent($aEvent)
  1880. {
  1881. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->deleteEvent(array('id' => (int)$aEvent['id'])))
  1882. return false;
  1883. $this->onDelete($aEvent);
  1884. return true;
  1885. }
  1886. public function addAttachLink($aValues, $sDisplay = false)
  1887. {
  1888. $CNF = &$this->_oConfig->CNF;
  1889. if(!$sDisplay)
  1890. $sDisplay = $this->_oConfig->getObject('form_display_attach_link_add');
  1891. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $sDisplay, $this->_oTemplate);
  1892. if(!$oForm)
  1893. return array('message' => '_sys_txt_error_occured');
  1894. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  1895. $oForm->aParams['csrf']['disable'] = true;
  1896. if(!empty($oForm->aParams['db']['submit_name'])) {
  1897. $sSubmitName = $oForm->aParams['db']['submit_name'];
  1898. if(!isset($oForm->aInputs[$sSubmitName])) {
  1899. if(isset($oForm->aInputs[$CNF['FIELD_CONTROLS']]))
  1900. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  1901. if(!is_numeric($mixedIndex) || empty($aInput['name']) || $aInput['name'] != $sSubmitName)
  1902. continue;
  1903. $aValues[$sSubmitName] = $aInput['value'];
  1904. }
  1905. }
  1906. else
  1907. $aValues[$sSubmitName] = $oForm->aInputs[$sSubmitName]['value'];
  1908. }
  1909. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  1910. $oForm->initChecker(array(), $aValues);
  1911. if(!$oForm->isSubmittedAndValid())
  1912. return array('message' => '_sys_txt_error_occured');
  1913. return $this->_addLink($oForm);
  1914. }
  1915. public function getFormAttachLink()
  1916. {
  1917. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $this->_oConfig->getObject('form_display_attach_link_add'), $this->_oTemplate);
  1918. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_attach_link_form/';
  1919. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  1920. $oForm->initChecker();
  1921. if($oForm->isSubmittedAndValid())
  1922. return $this->_addLink($oForm);
  1923. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  1924. }
  1925. public function getFormPost($aParams = array())
  1926. {
  1927. $iUserId = $this->getUserId();
  1928. $oForm = $this->getFormPostObject($aParams);
  1929. $oForm->initChecker();
  1930. $bAjaxMode = $oForm->isAjaxMode();
  1931. $bDynamicMode = $bAjaxMode;
  1932. if($oForm->isSubmittedAndValid()) {
  1933. list($sUserName) = $this->getUserInfo($iUserId);
  1934. $sType = $oForm->getCleanValue('type');
  1935. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  1936. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  1937. $aContent = array();
  1938. //--- Process Text ---//
  1939. $sText = $oForm->getCleanValue('text');
  1940. $sText = $this->_prepareTextForSave($sText);
  1941. $bText = !empty($sText);
  1942. if($bText)
  1943. $aContent['text'] = $sText;
  1944. //--- Process Context and Privacy ---//
  1945. $iOwnerId = (int)$oForm->getCleanValue('owner_id');
  1946. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  1947. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  1948. if(empty($iObjectPrivacyView))
  1949. $iObjectPrivacyView = $iObjectPrivacyViewDefault;
  1950. else if($iObjectPrivacyView < 0)
  1951. $iOwnerId = abs($iObjectPrivacyView);
  1952. //--- Process Link ---//
  1953. $aLinkIds = $oForm->getCleanValue('link');
  1954. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  1955. //--- Process Media ---//
  1956. $aPhotoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_PHOTO);
  1957. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  1958. $aVideoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_VIDEO);
  1959. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  1960. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds) {
  1961. $oForm->aInputs['text']['error'] = _t('_bx_timeline_txt_err_empty_post');
  1962. $oForm->setValid(false);
  1963. return $this->_prepareResponse(array('form' => $oForm->getCode($bDynamicMode), 'form_id' => $oForm->id), $bAjaxMode);
  1964. }
  1965. $sTitle = $bText ? $this->_oConfig->getTitle($sText) : $this->_oConfig->getTitleDefault($bLinkIds, $bPhotoIds, $bVideoIds);
  1966. $sDescription = _t('_bx_timeline_txt_user_added_sample', '{profile_name}', _t('_bx_timeline_txt_sample_with_article'));
  1967. /**
  1968. * Unset 'text' input because its data was already processed
  1969. * and will be saved via additional values which were passed
  1970. * to BxDolForm::insert method.
  1971. */
  1972. unset($oForm->aInputs['text']);
  1973. $iId = $oForm->insert(array(
  1974. 'owner_id' => $iOwnerId,
  1975. 'object_id' => $iUserId,
  1976. 'object_privacy_view' => $iObjectPrivacyView,
  1977. 'content' => serialize($aContent),
  1978. 'title' => $sTitle,
  1979. 'description' => $sDescription
  1980. ));
  1981. if(!empty($iId)) {
  1982. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  1983. if($bText)
  1984. $oMetatags->metaAdd($iId, $sText);
  1985. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  1986. //--- Process Link ---//
  1987. if($bLinkIds)
  1988. foreach($aLinkIds as $iLinkId)
  1989. $this->_oDb->saveLink($iId, $iLinkId);
  1990. //--- Process Media ---//
  1991. if($bPhotoIds)
  1992. $this->_saveMedia(BX_TIMELINE_MEDIA_PHOTO, $iId, $aPhotoIds);
  1993. if($bVideoIds)
  1994. $this->_saveMedia(BX_TIMELINE_MEDIA_VIDEO, $iId, $aVideoIds);
  1995. $this->onPost($iId);
  1996. return $this->_prepareResponse(array('id' => $iId), $bAjaxMode, array(
  1997. 'redirect' => $this->_oConfig->getItemViewUrl(array('id' => $iId))
  1998. ));
  1999. }
  2000. return $this->_prepareResponse(array('message' => _t('_bx_timeline_txt_err_cannot_perform_action')), $bAjaxMode);
  2001. }
  2002. return $this->_prepareResponse(array('form' => $oForm->getCode($bDynamicMode), 'form_id' => $oForm->id), $bAjaxMode && $oForm->isSubmitted());
  2003. }
  2004. public function getFormEdit($iId, $aParams = array(), $aBrowseParams = array())
  2005. {
  2006. $CNF = &$this->_oConfig->CNF;
  2007. $sJsObjectView = $this->_oConfig->getJsObjectView($aBrowseParams);
  2008. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  2009. if(empty($aEvent) || !is_array($aEvent))
  2010. return array();
  2011. $aContent = unserialize($aEvent['content']);
  2012. if(is_array($aContent) && !empty($aContent['text']))
  2013. $aEvent['text'] = $aContent['text'];
  2014. $bDynamicMode = isset($aParams['dynamic_mode']) ? (bool)$aParams['dynamic_mode'] : false;
  2015. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  2016. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_edit';
  2017. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  2018. $oForm->setId($this->_oConfig->getHtmlIds('view', 'edit_form') . $iId);
  2019. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'edit/' . $iId ;
  2020. if(!empty($aBrowseParams) && is_array($aBrowseParams))
  2021. $oForm->aFormAttrs['action'] = $this->_oConfig->addBrowseParams($oForm->aFormAttrs['action'], $aBrowseParams);
  2022. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  2023. if(!is_numeric($mixedIndex))
  2024. continue;
  2025. $oForm->aInputs[$CNF['FIELD_CONTROLS']][$mixedIndex]['attrs'] = bx_replace_markers($aInput['attrs'], array(
  2026. 'js_object_view' => $sJsObjectView,
  2027. 'content_id' => $iId
  2028. ));
  2029. }
  2030. $oForm->initChecker($aEvent);
  2031. if($oForm->isSubmittedAndValid()) {
  2032. $aContent = array();
  2033. //--- Process Text ---//
  2034. $sText = $oForm->getCleanValue('text');
  2035. $sText = $this->_prepareTextForSave($sText);
  2036. $bText = !empty($sText);
  2037. unset($oForm->aInputs['text']);
  2038. if($bText)
  2039. $aContent['text'] = $sText;
  2040. $aValsToAdd = array(
  2041. 'content' => serialize($aContent)
  2042. );
  2043. //--- Process Privacy ---//
  2044. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  2045. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  2046. if(empty($iObjectPrivacyView))
  2047. $aValsToAdd = array_merge($aValsToAdd, array(
  2048. 'object_privacy_view' => $iObjectPrivacyViewDefault
  2049. ));
  2050. else if($iObjectPrivacyView < 0)
  2051. $aValsToAdd = array_merge($aValsToAdd, array(
  2052. 'owner_id' => abs($iObjectPrivacyView),
  2053. 'object_privacy_view' => $iObjectPrivacyViewDefault
  2054. ));
  2055. if(!$oForm->update($iId, $aValsToAdd))
  2056. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  2057. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  2058. if($bText)
  2059. $oMetatags->metaAdd($iId, $sText);
  2060. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  2061. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iId);
  2062. $this->_oDb->deleteCache(array('event_id' => $iId));
  2063. return array(
  2064. 'id' => $iId
  2065. );
  2066. }
  2067. return array(
  2068. 'id' => $iId,
  2069. 'form' => $oForm->getCode($bDynamicMode),
  2070. 'form_id' => $oForm->id,
  2071. 'eval' => $sJsObjectView . '.onEditPost(oData)'
  2072. );
  2073. }
  2074. public function getFormPostObject($aParams)
  2075. {
  2076. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  2077. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_add';
  2078. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  2079. $sParamsKey = 'ajax_mode';
  2080. if(isset($aParams[$sParamsKey]) && is_bool($aParams[$sParamsKey]))
  2081. $oForm->setAjaxMode((bool)$aParams[$sParamsKey]);
  2082. $sParamsKey = 'visibility_autoselect';
  2083. if(isset($aParams[$sParamsKey]) && is_bool($aParams[$sParamsKey]))
  2084. $oForm->setVisibilityAutoselect((bool)$aParams[$sParamsKey]);
  2085. $oForm->init();
  2086. return $oForm;
  2087. }
  2088. public function getCmtsObject($sSystem, $iId)
  2089. {
  2090. if(empty($sSystem) || (int)$iId == 0)
  2091. return false;
  2092. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2093. if(!$oCmts || !$oCmts->isEnabled())
  2094. return false;
  2095. return $oCmts;
  2096. }
  2097. public function getViewObject($sSystem, $iId)
  2098. {
  2099. if(empty($sSystem) || (int)$iId == 0)
  2100. return false;
  2101. $oView = BxDolView::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2102. if(!$oView || !$oView->isEnabled())
  2103. return false;
  2104. return $oView;
  2105. }
  2106. public function getVoteObject($sSystem, $iId)
  2107. {
  2108. if(empty($sSystem) || (int)$iId == 0)
  2109. return false;
  2110. $oVote = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2111. if(!$oVote || !$oVote->isEnabled())
  2112. return false;
  2113. return $oVote;
  2114. }
  2115. public function getReactionObject($sSystem, $iId)
  2116. {
  2117. if(empty($sSystem) || (int)$iId == 0)
  2118. return false;
  2119. $oReaction = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2120. if(!$oReaction || !$oReaction->isEnabled())
  2121. return false;
  2122. return $oReaction;
  2123. }
  2124. public function getScoreObject($sSystem, $iId)
  2125. {
  2126. if(empty($sSystem) || (int)$iId == 0)
  2127. return false;
  2128. $oScore = BxDolScore::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2129. if(!$oScore || !$oScore->isEnabled())
  2130. return false;
  2131. return $oScore;
  2132. }
  2133. public function getReportObject($sSystem, $iId)
  2134. {
  2135. if(empty($sSystem) || (int)$iId == 0)
  2136. return false;
  2137. $oReport = BxDolReport::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2138. if(!$oReport || !$oReport->isEnabled())
  2139. return false;
  2140. return $oReport;
  2141. }
  2142. public function getAttachmentsMenuObject()
  2143. {
  2144. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post_attachments'), $this->_oTemplate);
  2145. $oMenu->addMarkers(array(
  2146. 'js_object' => $this->_oConfig->getJsObject('post'),
  2147. ));
  2148. return $oMenu;
  2149. }
  2150. public function getManageMenuObject()
  2151. {
  2152. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'), $this->_oTemplate);
  2153. }
  2154. public function getCacheItemObject()
  2155. {
  2156. $oCacheEngine = bx_instance('BxDolCache' . $this->_oConfig->getCacheItemEngine());
  2157. if(!$oCacheEngine->isAvailable())
  2158. $oCacheEngine = bx_instance('BxDolCacheFile');
  2159. return $oCacheEngine;
  2160. }
  2161. //--- Check permissions methods ---//
  2162. public function isModerator()
  2163. {
  2164. $sModule = $this->getName();
  2165. $iUserId = (int)$this->getUserId();
  2166. $aCheckResult = checkActionModule($iUserId, 'edit', $sModule);
  2167. if($aCheckResult[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2168. return true;
  2169. $aCheckResult = checkActionModule($iUserId, 'delete', $sModule);
  2170. if($aCheckResult[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2171. return true;
  2172. return false;
  2173. }
  2174. public function isAllowedPost($bPerform = false)
  2175. {
  2176. if(isAdmin())
  2177. return true;
  2178. $iUserId = $this->getUserId();
  2179. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  2180. if(!empty($this->_iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId)) !== false) {
  2181. if($oProfileOwner->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  2182. return _t('_sys_txt_access_denied');
  2183. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_post', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2184. }
  2185. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2186. }
  2187. public function isAllowedView($aEvent, $bPerform = false)
  2188. {
  2189. $CNF = $this->_oConfig->CNF;
  2190. $mixedResult = BxDolProfile::getInstance($aEvent[$CNF['FIELD_OWNER_ID']])->checkAllowedProfileView();
  2191. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  2192. return false;
  2193. return true;
  2194. }
  2195. public function isAllowedEdit($aEvent, $bPerform = false)
  2196. {
  2197. if(!isLogged())
  2198. return false;
  2199. //--- System posts and Reposts cannot be edited at all.
  2200. if(!$this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) || $aEvent['type'] == $this->_oConfig->getPrefix('common_post') . 'repost')
  2201. return false;
  2202. if(isAdmin())
  2203. return true;
  2204. $iUserId = (int)$this->getUserId();
  2205. $iOwnerId = (int)$aEvent['owner_id'];
  2206. $iObjectId = abs((int)$aEvent['object_id']);
  2207. if($iObjectId == $iUserId && $this->_oConfig->isAllowEdit())
  2208. return true;
  2209. $aCheckResult = checkActionModule($iUserId, 'edit', $this->getName(), $bPerform);
  2210. if(!empty($iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($iOwnerId)) !== false)
  2211. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_edit', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2212. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2213. }
  2214. public function isAllowedDelete($aEvent, $bPerform = false)
  2215. {
  2216. if(!isLogged())
  2217. return false;
  2218. if(isAdmin())
  2219. return true;
  2220. $iUserId = (int)$this->getUserId();
  2221. $iOwnerId = (int)$aEvent['owner_id'];
  2222. $iObjectId = abs((int)$aEvent['object_id']);
  2223. if((($iOwnerId == $iUserId && $this->_oConfig->isAllowDelete()) || ($this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && $iObjectId == $iUserId)))
  2224. return true;
  2225. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  2226. if(!empty($iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($iOwnerId)) !== false)
  2227. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_delete', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2228. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2229. }
  2230. public function isAllowedComment($aEvent, $bPerform = false)
  2231. {
  2232. $mixedComments = $this->getCommentsData($aEvent['comments']);
  2233. if($mixedComments === false)
  2234. return false;
  2235. list($sSystem, $iObjectId) = $mixedComments;
  2236. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  2237. if($oCmts->isViewAllowed() !== CHECK_ACTION_RESULT_ALLOWED)
  2238. return false;
  2239. $oCmts->addCssJs();
  2240. $bResult = true;
  2241. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false) {
  2242. if($oProfileOwner->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  2243. return false;
  2244. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_comment', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2245. }
  2246. return $bResult;
  2247. }
  2248. public function isAllowedViewCounter($aEvent, $bPerform = false)
  2249. {
  2250. $mixedViews = $this->getViewsData($aEvent['views']);
  2251. if($mixedViews === false)
  2252. return false;
  2253. list($sSystem, $iObjectId) = $mixedViews;
  2254. $oView = $this->getViewObject($sSystem, $iObjectId);
  2255. if(!$oView->isAllowedViewView($bPerform))
  2256. return false;
  2257. $bResult = true;
  2258. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2259. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view_counter', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2260. return $bResult;
  2261. }
  2262. public function isAllowedVote($aEvent, $bPerform = false)
  2263. {
  2264. $mixedVotes = $this->getVotesData($aEvent['votes']);
  2265. if($mixedVotes === false)
  2266. return false;
  2267. list($sSystem, $iObjectId) = $mixedVotes;
  2268. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  2269. if(!$oVote->isAllowedVote($bPerform))
  2270. return false;
  2271. $bResult = true;
  2272. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2273. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2274. return $bResult;
  2275. }
  2276. public function isAllowedReaction($aEvent, $bPerform = false)
  2277. {
  2278. $mixedReactions = $this->getReactionsData($aEvent['reactions']);
  2279. if($mixedReactions === false)
  2280. return false;
  2281. list($sSystem, $iObjectId) = $mixedReactions;
  2282. $oReaction = $this->getReactionObject($sSystem, $iObjectId);
  2283. if(!$oReaction->isAllowedVote($bPerform))
  2284. return false;
  2285. $bResult = true;
  2286. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2287. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_reaction', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2288. return $bResult;
  2289. }
  2290. public function isAllowedScore($aEvent, $bPerform = false)
  2291. {
  2292. $mixedScores = $this->getScoresData($aEvent['scores']);
  2293. if($mixedScores === false)
  2294. return false;
  2295. list($sSystem, $iObjectId) = $mixedScores;
  2296. $oScore = $this->getScoreObject($sSystem, $iObjectId);
  2297. if(!$oScore->isAllowedVote($bPerform))
  2298. return false;
  2299. $bResult = true;
  2300. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2301. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_score', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2302. return $bResult;
  2303. }
  2304. public function isAllowedReport($aEvent, $bPerform = false)
  2305. {
  2306. $mixedReports = $this->getReportsData($aEvent['reports']);
  2307. if($mixedReports === false)
  2308. return false;
  2309. list($sSystem, $iObjectId) = $mixedReports;
  2310. $oReport = $this->getReportObject($sSystem, $iObjectId);
  2311. if(!$oReport->isAllowedReport($bPerform))
  2312. return false;
  2313. $bResult = true;
  2314. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2315. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_report', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2316. return $bResult;
  2317. }
  2318. public function isAllowedRepost($aEvent, $bPerform = false)
  2319. {
  2320. $iUserId = (int)$this->getUserId();
  2321. if($iUserId == 0)
  2322. return false;
  2323. $iPrivacy = (int)$aEvent['object_privacy_view'];
  2324. if($iPrivacy >= 0 && !in_array($iPrivacy, array(BX_DOL_PG_ALL, BX_DOL_PG_MEMBERS)))
  2325. return false;
  2326. if(isAdmin())
  2327. return true;
  2328. $aCheckResult = checkActionModule($iUserId, 'repost', $this->getName(), $bPerform);
  2329. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2330. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_repost', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2331. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2332. }
  2333. public function isAllowedSend($aEvent, $bPerform = false)
  2334. {
  2335. if(!$this->_oDb->isEnabledByName('bx_convos'))
  2336. return false;
  2337. if(isAdmin())
  2338. return true;
  2339. $iUserId = (int)$this->getUserId();
  2340. if($iUserId == 0)
  2341. return false;
  2342. $aCheckResult = checkActionModule($iUserId, 'send', $this->getName(), $bPerform);
  2343. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2344. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_send', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2345. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2346. }
  2347. /**
  2348. * Pin - "Pin here" - pin the post on Profile Timeline for profile owner.
  2349. * Can be done by profile owner for himself or by admin for profile owner to see.
  2350. * @param type $aEvent
  2351. * @param type $bPerform
  2352. * @return boolean
  2353. */
  2354. public function isAllowedPin($aEvent, $bPerform = false)
  2355. {
  2356. if((int)$aEvent['pinned'] != 0)
  2357. return false;
  2358. return $this->_isAllowedPin($aEvent, $bPerform);
  2359. }
  2360. public function isAllowedUnpin($aEvent, $bPerform = false)
  2361. {
  2362. if((int)$aEvent['pinned'] == 0)
  2363. return false;
  2364. return $this->_isAllowedPin($aEvent, $bPerform);
  2365. }
  2366. /**
  2367. * Stick - "Pin for All" - pin the post on Public Timeline for everybody to see.
  2368. * Is available for Administrators/Moderators only.
  2369. * @param type $aEvent
  2370. * @param type $bPerform
  2371. * @return boolean
  2372. */
  2373. public function isAllowedStick($aEvent, $bPerform = false)
  2374. {
  2375. if((int)$aEvent['sticked'] != 0)
  2376. return false;
  2377. return $this->_isAllowedStick($aEvent, $bPerform);
  2378. }
  2379. public function isAllowedUnstick($aEvent, $bPerform = false)
  2380. {
  2381. if((int)$aEvent['sticked'] == 0)
  2382. return false;
  2383. return $this->_isAllowedStick($aEvent, $bPerform);
  2384. }
  2385. public function isAllowedPromote($aEvent, $bPerform = false)
  2386. {
  2387. if((int)$aEvent['promoted'] != 0)
  2388. return false;
  2389. return $this->_isAllowedPromote($aEvent, $bPerform);
  2390. }
  2391. public function isAllowedUnpromote($aEvent, $bPerform = false)
  2392. {
  2393. if((int)$aEvent['promoted'] == 0)
  2394. return false;
  2395. return $this->_isAllowedPromote($aEvent, $bPerform);
  2396. }
  2397. public function isAllowedMore($aEvent, $bPerform = false)
  2398. {
  2399. $oMoreMenu = $this->getManageMenuObject();
  2400. $oMoreMenu->setEventById($aEvent['id']);
  2401. return $oMoreMenu->isVisible();
  2402. }
  2403. public function checkAllowedView ($aContentInfo, $isPerformAction = false)
  2404. {
  2405. if(!$this->isAllowedView($aContentInfo, $isPerformAction))
  2406. return _t('_sys_txt_access_denied');
  2407. return CHECK_ACTION_RESULT_ALLOWED;
  2408. }
  2409. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  2410. {
  2411. $CNF = $this->_oConfig->CNF;
  2412. $iOwner = (int)$aContentInfo[$CNF['FIELD_OWNER_ID']];
  2413. if($iOwner == 0) //--- in case of Public Timeline.
  2414. return CHECK_ACTION_RESULT_ALLOWED;
  2415. $oOwner = BxDolProfile::getInstance($iOwner);
  2416. if(!$oOwner) //--- in case of non-existed Timeline owner.
  2417. return _t('_sys_txt_access_denied');
  2418. $mixedResult = $oOwner->checkAllowedProfileView();
  2419. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  2420. return $mixedResult;
  2421. return CHECK_ACTION_RESULT_ALLOWED;
  2422. }
  2423. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  2424. {
  2425. $sError = '_sys_txt_access_denied';
  2426. $aContentInfo = $this->_oTemplate->getDataCached($aContentInfo);
  2427. if($aContentInfo === false)
  2428. return _t($sError);
  2429. if(!$this->isAllowedComment($aContentInfo, $isPerformAction))
  2430. return _t($sError);
  2431. return CHECK_ACTION_RESULT_ALLOWED;
  2432. }
  2433. public function onPost($iContentId)
  2434. {
  2435. $CNF = &$this->_oConfig->CNF;
  2436. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2437. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  2438. //--- Request event's data from content module and update it in the Timeline DB.
  2439. $this->_oTemplate->getDataCached($aEvent);
  2440. $sPostType = 'system';
  2441. $iSenderId = $iObjectAuthorId = (int)$aEvent['owner_id'];
  2442. }
  2443. else {
  2444. $sPostType = 'common';
  2445. $iSenderId = $iObjectAuthorId = (int)$aEvent['object_id'];
  2446. }
  2447. //--- Event -> Post/Defer for Alerts Engine ---//
  2448. $sAction = ($aEvent[$CNF['FIELD_STATUS']] == BX_TIMELINE_STATUS_AWAITING ? 'defer' : 'post') . '_' . $sPostType;
  2449. bx_alert($this->_oConfig->getObject('alert'), $sAction, $iContentId, $iSenderId, array(
  2450. 'owner_id' => $aEvent['owner_id'],
  2451. 'object_author_id' => $iObjectAuthorId,
  2452. 'privacy_view' => $aEvent['object_privacy_view'],
  2453. ));
  2454. //--- Event -> Post for Alerts Engine ---//
  2455. }
  2456. public function onPublished($iContentId)
  2457. {
  2458. $CNF = &$this->_oConfig->CNF;
  2459. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2460. //--- Clear Item cache
  2461. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iContentId);
  2462. //--- Clear Feed cache
  2463. $this->_oDb->deleteCache(array('context_id' => $aEvent[$CNF['FIELD_OWNER_ID']]));
  2464. $this->onPost($iContentId);
  2465. }
  2466. public function onFailed($iContentId)
  2467. {
  2468. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2469. //--- Clear Item cache
  2470. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iContentId);
  2471. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  2472. //--- Request event's data from content module and update it in the Timeline DB.
  2473. $this->_oTemplate->getDataCached($aEvent);
  2474. $sPostType = 'system';
  2475. $iSenderId = $iObjectAuthorId = (int)$aEvent['owner_id'];
  2476. }
  2477. else {
  2478. $sPostType = 'common';
  2479. $iSenderId = $iObjectAuthorId = (int)$aEvent['object_id'];
  2480. }
  2481. //--- Event -> Fail for Alerts Engine ---//
  2482. bx_alert($this->_oConfig->getObject('alert'), 'fail_' . $sPostType, $iContentId, $iSenderId, array(
  2483. 'owner_id' => $aEvent['owner_id'],
  2484. 'object_author_id' => $iObjectAuthorId,
  2485. 'privacy_view' => $aEvent['object_privacy_view'],
  2486. ));
  2487. //--- Event -> Post for Alerts Engine ---//
  2488. }
  2489. public function onRepost($iContentId, $aReposted = array())
  2490. {
  2491. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2492. if(empty($aReposted)) {
  2493. $aContent = unserialize($aEvent['content']);
  2494. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  2495. if(empty($aReposted) || !is_array($aReposted))
  2496. return;
  2497. }
  2498. $iUserId = $this->getUserId();
  2499. $this->_oDb->insertRepostTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aReposted['id']);
  2500. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts']);
  2501. //--- Timeline -> Update for Alerts Engine ---//
  2502. bx_alert($this->_oConfig->getObject('alert'), 'repost', $aReposted['id'], $iUserId, array(
  2503. 'privacy_view' => $aEvent['object_privacy_view'],
  2504. 'object_author_id' => $aReposted['owner_id'],
  2505. 'repost_id' => $iContentId,
  2506. ));
  2507. //--- Timeline -> Update for Alerts Engine ---//
  2508. }
  2509. public function onDelete($aEvent)
  2510. {
  2511. $iUserId = $this->getUserId();
  2512. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  2513. $sCommonPostComment = $this->_oConfig->getObject('comment');
  2514. //--- Delete comments for Common posts.
  2515. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  2516. $oComments = $this->getCmtsObject($sCommonPostComment, $aEvent['id']);
  2517. if($oComments !== false)
  2518. $oComments->onObjectDelete($aEvent['id']);
  2519. }
  2520. //--- Delete attached photos, videos and links when common event was deleted.
  2521. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  2522. $this->_deleteMedia(BX_TIMELINE_MEDIA_PHOTO, $aEvent['id']);
  2523. $this->_deleteMedia(BX_TIMELINE_MEDIA_VIDEO, $aEvent['id']);
  2524. $this->_deleteLinks($aEvent['id']);
  2525. }
  2526. //--- Update parent event when repost event was deleted.
  2527. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  2528. if($bRepost) {
  2529. $this->_oDb->deleteRepostTrack($aEvent['id']);
  2530. $aContent = unserialize($aEvent['content']);
  2531. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  2532. if(!empty($aReposted) && is_array($aReposted))
  2533. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts'], -1);
  2534. }
  2535. //--- Find and delete repost events when parent event was deleted.
  2536. $bSystem = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']);
  2537. $aRepostEvents = $this->_oDb->getEvents(array('browse' => 'reposted_by_descriptor', 'type' => $aEvent['type']));
  2538. foreach($aRepostEvents as $aRepostEvent) {
  2539. $aContent = unserialize($aRepostEvent['content']);
  2540. if(isset($aContent['type']) && $aContent['type'] == $aEvent['type'] && isset($aContent['object_id']) && (($bSystem && (int)$aContent['object_id'] == (int)$aEvent['object_id']) || (!$bSystem && (int)$aContent['object_id'] == (int)$aEvent['id'])) && (int)$this->_oDb->deleteEvent(array('id' => (int)$aRepostEvent['id'])) > 0) {
  2541. $oComments = $this->getCmtsObject($sCommonPostComment, $aRepostEvent['id']);
  2542. if($oComments !== false)
  2543. $oComments->onObjectDelete($aRepostEvent['id']);
  2544. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aEvent['id'], $iUserId, array(
  2545. 'repost_id' => $aRepostEvent['id'],
  2546. ));
  2547. }
  2548. }
  2549. //--- Delete associated meta.
  2550. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  2551. $oMetatags->onDeleteContent($aEvent['id']);
  2552. //--- Event -> Delete for Alerts Engine ---//
  2553. if($bRepost)
  2554. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aReposted['id'], $iUserId, array(
  2555. 'repost_id' => $aEvent['id'],
  2556. ));
  2557. else
  2558. bx_alert($this->_oConfig->getObject('alert'), 'delete', $aEvent['id'], $iUserId);
  2559. //--- Event -> Delete for Alerts Engine ---//
  2560. }
  2561. public function getParams($sView = '', $sType = '', $iOwnerId = 0, $iStart = 0, $iPerPage = 0, $sFilter = BX_TIMELINE_FILTER_ALL, $aModules = array(), $iTimeline = 0)
  2562. {
  2563. return $this->_prepareParams(array(
  2564. 'view' => $sView,
  2565. 'type' => $sType,
  2566. 'owner_id' => $iOwnerId,
  2567. 'start' => $iStart,
  2568. 'per_page' => $iPerPage,
  2569. 'timeline' => $iTimeline,
  2570. 'filter' => $sFilter,
  2571. 'modules' => $aModules
  2572. ));
  2573. }
  2574. public function getParamsExt($aParams = array())
  2575. {
  2576. return $this->_prepareParams($aParams);
  2577. }
  2578. public function getViewsData(&$aViews)
  2579. {
  2580. if(empty($aViews) || !is_array($aViews))
  2581. return false;
  2582. $sSystem = isset($aViews['system']) ? $aViews['system'] : '';
  2583. $iObjectId = isset($aViews['object_id']) ? (int)$aViews['object_id'] : 0;
  2584. $iCount = isset($aViews['count']) ? (int)$aViews['count'] : 0;
  2585. if($sSystem == '' || $iObjectId == 0)
  2586. return false;
  2587. return array($sSystem, $iObjectId, $iCount);
  2588. }
  2589. public function getVotesData(&$aVotes)
  2590. {
  2591. if(empty($aVotes) || !is_array($aVotes))
  2592. return false;
  2593. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  2594. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  2595. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  2596. if($sSystem == '' || $iObjectId == 0)
  2597. return false;
  2598. return array($sSystem, $iObjectId, $iCount);
  2599. }
  2600. public function getReactionsData(&$aReactions)
  2601. {
  2602. if(empty($aReactions) || !is_array($aReactions))
  2603. return false;
  2604. $sSystem = isset($aReactions['system']) ? $aReactions['system'] : '';
  2605. $iObjectId = isset($aReactions['object_id']) ? (int)$aReactions['object_id'] : 0;
  2606. $iCount = isset($aReactions['count']) ? (int)$aReactions['count'] : 0;
  2607. if($sSystem == '' || $iObjectId == 0)
  2608. return false;
  2609. return array($sSystem, $iObjectId, $iCount);
  2610. }
  2611. public function getScoresData(&$aScores)
  2612. {
  2613. if(empty($aScores) || !is_array($aScores))
  2614. return false;
  2615. $sSystem = isset($aScores['system']) ? $aScores['system'] : '';
  2616. $iObjectId = isset($aScores['object_id']) ? (int)$aScores['object_id'] : 0;
  2617. $iScore = isset($aScores['score']) ? (int)$aScores['score'] : 0;
  2618. if($sSystem == '' || $iObjectId == 0)
  2619. return false;
  2620. return array($sSystem, $iObjectId, $iScore);
  2621. }
  2622. public function getReportsData(&$aReports)
  2623. {
  2624. if(empty($aReports) || !is_array($aReports))
  2625. return false;
  2626. $sSystem = isset($aReports['system']) ? $aReports['system'] : '';
  2627. $iObjectId = isset($aReports['object_id']) ? (int)$aReports['object_id'] : 0;
  2628. $iCount = isset($aReports['count']) ? (int)$aReports['count'] : 0;
  2629. if($sSystem == '' || $iObjectId == 0)
  2630. return false;
  2631. return array($sSystem, $iObjectId, $iCount);
  2632. }
  2633. public function getCommentsData(&$aComments)
  2634. {
  2635. if(empty($aComments) || !is_array($aComments))
  2636. return false;
  2637. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  2638. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  2639. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  2640. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  2641. return false;
  2642. return array($sSystem, $iObjectId, $iCount);
  2643. }
  2644. public function getUserInfo($iUserId = 0)
  2645. {
  2646. $iLoggedId = $this->getUserId();
  2647. $iUserId = (int)$iUserId;
  2648. return parent::getUserInfo($iUserId);
  2649. }
  2650. /**
  2651. * Protected Methods
  2652. */
  2653. protected function _serviceGetBlockView($iProfileId = 0, $aBrowseParams = array())
  2654. {
  2655. if(empty($iProfileId) && bx_get('profile_id') !== false)
  2656. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  2657. if(empty($iProfileId) && isLogged())
  2658. $iProfileId = bx_get_logged_profile_id();
  2659. $aBrowseParams['owner_id'] = $iProfileId;
  2660. $aBlock = $this->_getBlockView($aBrowseParams);
  2661. if(!empty($aBlock))
  2662. return $aBlock;
  2663. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  2664. }
  2665. protected function _serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $aBrowseParams = array())
  2666. {
  2667. if(empty($sProfileModule))
  2668. return array();
  2669. if(empty($iProfileContentId) && bx_get('id') !== false)
  2670. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2671. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  2672. if(empty($oProfile))
  2673. return array();
  2674. $aBrowseParams['owner_id'] = $oProfile->id();
  2675. return $this->_getBlockView($aBrowseParams);
  2676. }
  2677. protected function _serviceGetBlockViewHome($aBrowseParams = array())
  2678. {
  2679. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  2680. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_home'), $sRssUrl);
  2681. return $this->_serviceGetBlockViewByType($aBrowseParams);
  2682. }
  2683. protected function _serviceGetBlockViewHot($aBrowseParams = array())
  2684. {
  2685. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  2686. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_hot'), $sRssUrl);
  2687. return $this->_serviceGetBlockViewByType($aBrowseParams);
  2688. }
  2689. protected function _serviceGetBlockViewByType($aBrowseParams = array())
  2690. {
  2691. $aParams = $this->_prepareParams($aBrowseParams);
  2692. $this->_iOwnerId = $aParams['owner_id'];
  2693. return array(
  2694. 'content' => $this->_oTemplate->getViewBlock($aParams)
  2695. );
  2696. }
  2697. protected function _getBlockPost($iProfileId, $aParams = array())
  2698. {
  2699. $this->_iOwnerId = $iProfileId;
  2700. if($this->isAllowedPost() !== true)
  2701. return array();
  2702. return array(
  2703. 'content' => $this->_oTemplate->getPostBlock($this->_iOwnerId, $aParams)
  2704. );
  2705. }
  2706. protected function _getBlockView($aBrowseParams = array())
  2707. {
  2708. if(empty($aBrowseParams['owner_id']))
  2709. return array();
  2710. $aParams = $this->_prepareParams($aBrowseParams);
  2711. if(empty($aParams['per_page']))
  2712. $aParams['per_page'] = $this->_oConfig->getPerPage('profile');
  2713. $this->_iOwnerId = $aParams['owner_id'];
  2714. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  2715. $mixedResult = $oProfileOwner->checkAllowedProfileView();
  2716. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  2717. return array('content' => MsgBox($mixedResult));
  2718. list($sUserName) = $this->getUserInfo($aParams['owner_id']);
  2719. $sView = $aParams['view'];
  2720. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_OWNER . '/' . $this->_iOwnerId . '/';
  2721. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  2722. $aMenu = array(
  2723. array('id' => $sView . '-view-all', 'name' => $sView . '-view-all', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_all'), 'active' => 1),
  2724. array('id' => $sView . '-view-owner', 'name' => $sView . '-view-owner', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_owner', $sUserName)),
  2725. array('id' => $sView . '-view-other', 'name' => $sView . '-view-other', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_other')),
  2726. array('id' => $sView . '-get-rss', 'name' => $sView . '-get-rss', 'class' => '', 'link' => $sRssUrl, 'onclick' => '', 'target' => '_blank', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  2727. );
  2728. $sContent = '';
  2729. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view', $this->_iOwnerId, $this->getUserId(), array('override_content' => &$sContent, 'params' => &$aParams, 'menu' => &$aMenu));
  2730. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $sView . '-view-all', 'menu_items' => $aMenu));
  2731. $oMenu->setSelected('', $sView . '-view-all');
  2732. if (!$sContent)
  2733. $sContent = $this->_oTemplate->getViewBlock($aParams);
  2734. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view'), $sRssUrl);
  2735. return array('content' => $sContent, 'menu' => $oMenu);
  2736. }
  2737. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  2738. {
  2739. $CNF = &$this->_oConfig->CNF;
  2740. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  2741. $sText = '';
  2742. if(isset($aContentInfo['content'])){
  2743. $aTmp = unserialize($aContentInfo['content']);
  2744. if(isset($aTmp['text']))
  2745. $sText = $aTmp['text'];
  2746. }
  2747. if(empty($sText) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  2748. $sText = $aContentInfo[$CNF['FIELD_TITLE']];
  2749. if(!empty($CNF['OBJECT_METATAGS']) && !empty($sText)) {
  2750. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  2751. $sText = $oMetatags->metaParse($aContentInfo[$CNF['FIELD_ID']], $sText);
  2752. }
  2753. return array(
  2754. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  2755. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  2756. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  2757. 'url' => $sUrl,
  2758. 'title' => '',
  2759. 'text' => $sText,
  2760. 'images' => array(),
  2761. 'videos' => array()
  2762. );
  2763. }
  2764. protected function _isAllowedPin($aEvent, $bPerform = false)
  2765. {
  2766. $iUserId = (int)$this->getUserId();
  2767. if($iUserId == 0)
  2768. return false;
  2769. if(isAdmin() || (int)$aEvent['owner_id'] == $iUserId || ((int)$aEvent['owner_id'] == 0 && $this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && (int)$aEvent['object_id'] == $iUserId))
  2770. return true;
  2771. $aCheckResult = checkActionModule($iUserId, 'pin', $this->getName(), $bPerform);
  2772. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2773. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_pin', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2774. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2775. }
  2776. protected function _isAllowedStick($aEvent, $bPerform = false)
  2777. {
  2778. $iUserId = (int)$this->getUserId();
  2779. if($iUserId == 0)
  2780. return false;
  2781. if(isAdmin())
  2782. return true;
  2783. $aCheckResult = checkActionModule($iUserId, 'stick', $this->getName(), $bPerform);
  2784. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2785. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_stick', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2786. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2787. }
  2788. protected function _isAllowedPromote($aEvent, $bPerform = false)
  2789. {
  2790. if(isAdmin())
  2791. return true;
  2792. $iUserId = (int)$this->getUserId();
  2793. if($iUserId == 0)
  2794. return false;
  2795. $aCheckResult = checkActionModule($iUserId, 'promote', $this->getName(), $bPerform);
  2796. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2797. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_promote', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2798. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2799. }
  2800. protected function _addLink(&$oForm)
  2801. {
  2802. $iUserId = $this->getUserId();
  2803. $sLink = $oForm->getCleanValue('url');
  2804. $aMatches = array();
  2805. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  2806. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  2807. $aSiteInfo = bx_get_site_info($sLink, array(
  2808. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  2809. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  2810. ));
  2811. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : _t('_Empty');
  2812. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : _t('_Empty');
  2813. $sMediaUrl = '';
  2814. if(!empty($aSiteInfo['thumbnailUrl']))
  2815. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  2816. else if(!empty($aSiteInfo['OGImage']))
  2817. $sMediaUrl = $aSiteInfo['OGImage'];
  2818. $iMediaId = 0;
  2819. $oStorage = null;
  2820. if(!empty($sMediaUrl)) {
  2821. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . BX_TIMELINE_MEDIA_PHOTO . 's'));
  2822. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  2823. }
  2824. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  2825. if(!empty($iId)) {
  2826. if(!empty($oStorage) && !empty($iMediaId))
  2827. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  2828. return array('id' => $iId, 'item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId));
  2829. }
  2830. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  2831. }
  2832. protected function _deleteLinks($iId)
  2833. {
  2834. $aLinks = $this->_oDb->getLinks($iId);
  2835. if(empty($aLinks) || !is_array($aLinks))
  2836. return;
  2837. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  2838. foreach($aLinks as $aLink)
  2839. if(!empty($aLink['media_id']))
  2840. $oStorage->deleteFile($aLink['media_id']);
  2841. $this->_oDb->deleteLinks($iId);
  2842. }
  2843. protected function _saveMedia($sType, $iId, $aItemIds)
  2844. {
  2845. if(empty($aItemIds) || !is_array($aItemIds))
  2846. return;
  2847. $iUserId = $this->getUserId();
  2848. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  2849. foreach($aItemIds as $iItemId)
  2850. if($this->_oDb->saveMedia($sType, $iId, $iItemId))
  2851. $oStorage->afterUploadCleanup($iItemId, $iUserId);
  2852. }
  2853. protected function _deleteMedia($sType, $iId)
  2854. {
  2855. $aItems = $this->_oDb->getMedia($sType, $iId);
  2856. if(empty($aItems) || !is_array($aItems))
  2857. return;
  2858. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  2859. foreach($aItems as $iItemId)
  2860. $oStorage->deleteFile($iItemId);
  2861. $this->_oDb->deleteMedia($sType, $iId);
  2862. }
  2863. protected function _prepareParams($aParams)
  2864. {
  2865. if(empty($aParams['name']))
  2866. $aParams['name'] = '';
  2867. if(empty($aParams['view']))
  2868. $aParams['view'] = BX_TIMELINE_VIEW_DEFAULT;
  2869. if(empty($aParams['type']))
  2870. $aParams['type'] = BX_TIMELINE_TYPE_DEFAULT;
  2871. if(empty($aParams['owner_id']))
  2872. $aParams['owner_id'] = $this->getUserId();
  2873. if(!isset($aParams['start']) || (int)$aParams['start'] < 0)
  2874. $aParams['start'] = 0;
  2875. if(!isset($aParams['per_page']) || (int)$aParams['per_page'] <= 0)
  2876. $aParams['per_page'] = isset($aParams['per_page_default']) && (int)$aParams['per_page_default'] > 0 ? $aParams['per_page_default'] : $this->_oConfig->getPerPage();
  2877. if(empty($aParams['timeline']) || (int)$aParams['timeline'] < 0)
  2878. $aParams['timeline'] = 0;
  2879. if(empty($aParams['filter']))
  2880. $aParams['filter'] = BX_TIMELINE_FILTER_ALL;
  2881. if(empty($aParams['modules']) || !is_array($aParams['modules']))
  2882. $aParams['modules'] = array();
  2883. if(empty($aParams['blink']) || !is_array($aParams['blink']))
  2884. $aParams['blink'] = array();
  2885. if($this->_oConfig->isHot())
  2886. $aParams['hot'] = $this->_oDb->getHot();
  2887. $aParams = array_merge($aParams, array(
  2888. 'browse' => 'list',
  2889. 'status' => BX_TIMELINE_STATUS_ACTIVE
  2890. ));
  2891. return $aParams;
  2892. }
  2893. protected function _prepareParamsGet()
  2894. {
  2895. $aParams = array();
  2896. $aParams['name'] = bx_get('name');
  2897. $aParams['name'] = $aParams['name'] !== false ? bx_process_input($aParams['name'], BX_DATA_TEXT) : '';
  2898. $aParams['view'] = bx_get('view');
  2899. $aParams['view'] = $aParams['view'] !== false ? bx_process_input($aParams['view'], BX_DATA_TEXT) : BX_TIMELINE_VIEW_DEFAULT;
  2900. $aParams['type'] = bx_get('type');
  2901. $aParams['type'] = $aParams['type'] !== false ? bx_process_input($aParams['type'], BX_DATA_TEXT) : BX_TIMELINE_TYPE_DEFAULT;
  2902. $aParams['owner_id'] = bx_get('owner_id');
  2903. $aParams['owner_id'] = $aParams['owner_id'] !== false ? bx_process_input($aParams['owner_id'], BX_DATA_INT) : $this->getUserId();
  2904. $aParams['start'] = bx_get('start');
  2905. $aParams['start'] = $aParams['start'] !== false ? bx_process_input($aParams['start'], BX_DATA_INT) : 0;
  2906. $aParams['per_page'] = bx_get('per_page');
  2907. $aParams['per_page'] = $aParams['per_page'] !== false ? bx_process_input($aParams['per_page'], BX_DATA_INT) : $this->_oConfig->getPerPage();
  2908. $aParams['timeline'] = bx_get('timeline');
  2909. $aParams['timeline'] = $aParams['timeline'] !== false ? bx_process_input($aParams['timeline'], BX_DATA_INT) : 0;
  2910. $aParams['filter'] = bx_get('filter');
  2911. $aParams['filter'] = $aParams['filter'] !== false ? bx_process_input($aParams['filter'], BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  2912. $aParams['modules'] = bx_get('modules');
  2913. $aParams['modules'] = $aParams['modules'] !== false ? bx_process_input($aParams['modules'], BX_DATA_TEXT) : array();
  2914. $aParams['blink'] = bx_get('blink');
  2915. $aParams['blink'] = $aParams['blink'] !== false ? explode(',', bx_process_input($aParams['blink'], BX_DATA_TEXT)) : array();
  2916. if($this->_oConfig->isHot())
  2917. $aParams['hot'] = $this->_oDb->getHot();
  2918. $aParams = array_merge($aParams, array(
  2919. 'browse' => 'list',
  2920. 'status' => BX_TIMELINE_STATUS_ACTIVE,
  2921. 'dynamic_mode' => true,
  2922. ));
  2923. return $aParams;
  2924. }
  2925. protected function _prepareTextForSave($s)
  2926. {
  2927. return bx_process_input($s, BX_DATA_HTML);
  2928. }
  2929. protected function _getFieldValue($sField, $iContentId)
  2930. {
  2931. $CNF = &$this->_oConfig->CNF;
  2932. if(empty($CNF[$sField]))
  2933. return false;
  2934. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2935. if(empty($aEvent) || empty($aEvent[$CNF[$sField]]))
  2936. return false;
  2937. return $aEvent[$CNF[$sField]];
  2938. }
  2939. /**
  2940. * Returns records for React Jot using OAuth2
  2941. * @param int $iProfileId
  2942. * @param string $sPage
  2943. * @param string $sTab
  2944. * @param int $iStart
  2945. * @param int $iPerPage
  2946. * @return array
  2947. */
  2948. public function serviceGetUserPosts($iProfileId = 0, $sPage = 'home', $sTab = 'hot', $iStart = 0, $iPerPage = 0)
  2949. {
  2950. $iProfileId = (int)$iProfileId ? (int)$iProfileId : bx_get_logged_profile_id();
  2951. if(empty($iProfileId))
  2952. return array(
  2953. 'code' => 1,
  2954. 'result' => array(),
  2955. 'message' => _t('_bx_timeline_txt_msg_no_profile_id'),
  2956. 'page' => $sPage,
  2957. 'tab' => $sTab
  2958. );
  2959. $sType = BX_TIMELINE_TYPE_DEFAULT;
  2960. $sView = BX_TIMELINE_VIEW_DEFAULT;
  2961. $sFilter = BX_TIMELINE_FILTER_ALL;
  2962. switch($sTab)
  2963. {
  2964. case 'feed':
  2965. $sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  2966. break;
  2967. case 'latest':
  2968. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  2969. $sFilter = BX_TIMELINE_FILTER_OWNER;
  2970. break;
  2971. case 'popular':
  2972. $sType = BX_TIMELINE_TYPE_HOT;
  2973. break;
  2974. case 'profile':
  2975. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  2976. $sFilter = BX_TIMELINE_FILTER_OWNER;
  2977. break;
  2978. }
  2979. $aModules = array();
  2980. if (!in_array($sPage, array('home', 'profile')))
  2981. $aModules = array($sPage);
  2982. $aParams = $this->getParams($sView, $sType, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules);
  2983. $aData = $this->_oDb->getEvents($aParams, true);
  2984. list($aEvents, $iCount) = $aData;
  2985. if(empty($aEvents) || !is_array($aEvents))
  2986. return array(
  2987. 'code' => 0,
  2988. 'result' => array(),
  2989. 'message' => _t('_bx_timeline_txt_msg_no_results'),
  2990. 'page' => $sPage,
  2991. 'tab' => $sTab
  2992. );
  2993. $aBrowseParams = array();
  2994. $aItems = array();
  2995. foreach($aEvents as $aEvent) {
  2996. $aResult = $this->_oTemplate->getData($aEvent, $aBrowseParams);
  2997. if($aResult === false)
  2998. continue;
  2999. $oOwnerProfile = BxDolProfile::getInstance($aResult['owner_id']);
  3000. $aFiles = array();
  3001. $aContent = &$aResult['content'];
  3002. if (!empty($aContent['image']))
  3003. $aFiles['images'] = $aContent['images'];
  3004. else
  3005. if (!empty($aContent['images_attach']))
  3006. $aFiles['images'] = $aContent['images_attach'];
  3007. if (!empty($aContent['videos']))
  3008. $aFiles['videos'] = $aContent['videos'];
  3009. else
  3010. if (!empty($aContent['videos_attach']))
  3011. $aFiles['videos'] = $aContent['videos_attach'];
  3012. if (!empty($aContent['files']))
  3013. $aFiles['files'] = $aContent['files'];
  3014. else
  3015. if (!empty($aContent['files_attach']))
  3016. $aFiles['files'] = $aContent['files_attach'];
  3017. $aItems[$aEvent['id']] = array_merge(array(
  3018. 'owner' => array(
  3019. 'icon' => $oOwnerProfile -> getThumb(),
  3020. 'name' => $oOwnerProfile -> getDisplayName(),
  3021. 'url' => $oOwnerProfile -> getUrl()
  3022. ),
  3023. 'sample' => !empty($aResult['sample']) ? _t($aResult['sample']) : _t('_bx_timeline_txt_sample'),
  3024. 'sample_action' => !empty($aResult['sample_action']) ? _t($aResult['sample_action']) : _t('_bx_timeline_txt_added_sample'),
  3025. 'url' => isset($aResult['url']) ? $aResult['url'] : '',
  3026. 'text' => isset($aContent['text']) ? strip_tags($aContent['text']) : '',
  3027. 'views' => isset($aResult['views']['count']) ? (int)$aResult['views']['count'] : 0,
  3028. 'votes' => isset($aResult['votes']['count']) ? (int)$aResult['votes']['count'] : 0,
  3029. 'reactions' => isset($aResult['reactions']['count']) ? (int)$aResult['reactions']['count'] : 0,
  3030. 'scores' => isset($aResult['scores']['count']) ? (int)$aResult['scores']['count'] : 0,
  3031. 'reports' => isset($aResult['reports']['count']) ? (int)$aResult['reports']['count'] : 0,
  3032. 'comments' => isset($aResult['comments']['count']) ? (int)$aResult['comments']['count'] : 0,
  3033. 'date' => isset($aResult['date']) ? $aResult['date'] : $aEvent['date'],
  3034. 'type' => stripos($aEvent['type'], 'timeline') !== FALSE ? 'bx_timeline' : $aEvent['type'],
  3035. 'event_type' => $aEvent['type'],
  3036. 'id' => $aEvent['id'],
  3037. 'content' => $aResult['content'],
  3038. 'title' => isset($aResult['title']) ? _t($aResult['title']) : '',
  3039. 'description' => isset($aResult['description']) ? $aResult['description'] : ''
  3040. ), $aFiles);
  3041. }
  3042. return array(
  3043. 'result' => $aItems,
  3044. 'code' => 0,
  3045. 'message' => '',
  3046. 'page' => $sPage,
  3047. 'tab' => $sTab,
  3048. 'total' => $iCount,
  3049. 'start' => (int)$iStart
  3050. );
  3051. }
  3052. }
  3053. /** @} */