BxTimelineModule.php 95 KB

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