BxTimelineModule.php 97 KB

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