BxTimelineModule.php 112 KB

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