BxTimelineModule.php 88 KB

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