BxTimelineModule.php 115 KB

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