BxTimelineModule.php 153 KB

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