BxTimelineModule.php 155 KB

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