BxTimelineModule.php 96 KB

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