BxTimelineModule.php 109 KB

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