BxTimelineModule.php 114 KB

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