BxTimelineModule.php 126 KB

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