BxTimelineModule.php 91 KB

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