BxTimelineModule.php 145 KB

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