BxTimelineModule.php 144 KB

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