BxTimelineModule.php 146 KB

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