BxTimelineModule.php 129 KB

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