BxTimelineModule.php 115 KB

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