BxTimelineModule.php 103 KB

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