BxTimelineModule.php 147 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786
  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_STATUS_ACTIVE', 'active');
  30. define('BX_TIMELINE_STATUS_AWAITING', 'awaiting');
  31. define('BX_TIMELINE_STATUS_FAILED', 'failed');
  32. define('BX_TIMELINE_STATUS_HIDDEN', 'hidden');
  33. define('BX_TIMELINE_STATUS_DELETED', 'deleted');
  34. define('BX_TIMELINE_MEDIA_PHOTO', 'photo');
  35. define('BX_TIMELINE_MEDIA_VIDEO', 'video');
  36. //--- Video Auto Play
  37. define('BX_TIMELINE_VAP_OFF', 'off');
  38. define('BX_TIMELINE_VAP_ON_MUTE', 'on_mute');
  39. define('BX_TIMELINE_VAP_ON', 'on');
  40. class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolContentInfoService
  41. {
  42. protected $_sJsPostObject;
  43. protected $_sJsViewObject;
  44. protected $_aPostElements;
  45. protected $_sJsOutlineObject;
  46. protected $_sDividerTemplate;
  47. protected $_sBalloonTemplate;
  48. protected $_sCmtPostTemplate;
  49. protected $_sCmtViewTemplate;
  50. protected $_sCmtTemplate;
  51. /**
  52. * Constructor
  53. */
  54. function __construct($aModule)
  55. {
  56. parent::__construct($aModule);
  57. }
  58. /**
  59. * ACTION METHODS
  60. */
  61. public function actionVideo($iEventId, $iVideoId)
  62. {
  63. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iEventId));
  64. if(empty($aEvent) || !is_array($aEvent))
  65. return;
  66. $aData = $this->_oTemplate->getDataCached($aEvent);
  67. if($aData === false || !isset($aData['content']['videos'][$iVideoId]))
  68. return;
  69. $oTemplate = BxDolTemplate::getInstance();
  70. $oTemplate->addJs(array(
  71. 'embedly-player.min.js'
  72. ));
  73. $oTemplate->setPageNameIndex (BX_PAGE_EMBED);
  74. $oTemplate->setPageContent ('page_main_code', $this->_oTemplate->getVideo($aEvent, $aData['content']['videos'][$iVideoId]));
  75. $oTemplate->getPageCode();
  76. }
  77. public function actionPost()
  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->getFormPost());
  84. }
  85. public function actionEdit($iId)
  86. {
  87. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  88. $aBrowseParams = array();
  89. if(bx_get('bp') !== false)
  90. $aBrowseParams = $this->_oConfig->getBrowseParams(bx_process_input(bx_get('bp')));
  91. $mixedAllowed = $this->isAllowedPost(true);
  92. if($mixedAllowed !== true)
  93. return echoJson(array('message' => strip_tags($mixedAllowed)));
  94. echoJson($this->getFormEdit($iId, array('dynamic_mode' => true), $aBrowseParams));
  95. }
  96. function actionPin()
  97. {
  98. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  99. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  100. if(empty($aEvent) || !is_array($aEvent))
  101. return echoJson(array('code' => 1));
  102. $aParams = $this->_prepareParamsGet();
  103. $this->_iOwnerId = $aParams['owner_id'];
  104. $mixedAllowed = $this->{'isAllowed' . ((int)$aEvent['pinned'] == 0 ? 'Pin' : 'Unpin')}($aEvent, true);
  105. if($mixedAllowed !== true)
  106. return echoJson(array('code' => 2, 'message' => strip_tags($mixedAllowed)));
  107. $aEvent['pinned'] = (int)$aEvent['pinned'] == 0 ? time() : 0;
  108. if(!$this->_oDb->updateEvent(array('pinned' => $aEvent['pinned']), array('id' => $iId)))
  109. return echoJson(array('code' => 3));
  110. echoJson(array(
  111. 'code' => 0,
  112. 'id' => $iId,
  113. 'eval' => $this->_oConfig->getJsObjectView($aParams) . '.onPinPost(oData)'
  114. ));
  115. }
  116. function actionStick()
  117. {
  118. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  119. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  120. if(empty($aEvent) || !is_array($aEvent))
  121. return echoJson(array('code' => 1));
  122. $aParams = $this->_prepareParamsGet();
  123. $this->_iOwnerId = $aParams['owner_id'];
  124. $mixedAllowed = $this->{'isAllowed' . ((int)$aEvent['sticked'] == 0 ? 'Stick' : 'Unstick')}($aEvent, true);
  125. if($mixedAllowed !== true)
  126. return echoJson(array('code' => 2, 'message' => strip_tags($mixedAllowed)));
  127. $aEvent['sticked'] = (int)$aEvent['sticked'] == 0 ? time() : 0;
  128. if(!$this->_oDb->updateEvent(array('sticked' => $aEvent['sticked']), array('id' => $iId)))
  129. return echoJson(array('code' => 3));
  130. echoJson(array(
  131. 'code' => 0,
  132. 'id' => $iId,
  133. 'eval' => $this->_oConfig->getJsObjectView($aParams) . '.onStickPost(oData)'
  134. ));
  135. }
  136. function actionPromote()
  137. {
  138. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  139. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  140. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  141. $sAction = (int)$aEvent['promoted'] == 0 ? 'promote' : 'unpromote';
  142. $mixedAllowed = $this->{'isAllowed' . ucfirst($sAction)}($aEvent, true);
  143. if($mixedAllowed !== true)
  144. return echoJson(array('code' => 1, 'message' => strip_tags($mixedAllowed)));
  145. $aEvent['promoted'] = (int)$aEvent['promoted'] == 0 ? time() : 0;
  146. if(!$this->_oDb->updateEvent(array('promoted' => $aEvent['promoted']), array('id' => $iId)))
  147. return echoJson(array('code' => 2));
  148. bx_alert($this->_oConfig->getObject('alert'), $sAction . 'd', $iId, (int)$this->getUserId(), array(
  149. 'owner_id' => $aEvent['owner_id'],
  150. 'object_id' => $aEvent['object_id'],
  151. 'object_author_id' => $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $aEvent['owner_id'] : $aEvent['object_id']
  152. ));
  153. echoJson(array(
  154. 'code' => 0,
  155. 'message' => _t('_bx_timeline_txt_msg_performed_action')
  156. ));
  157. }
  158. function actionDelete()
  159. {
  160. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  161. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  162. if(empty($aEvent) || !is_array($aEvent))
  163. return echoJson(array('code' => 1));
  164. $aParams = $this->_prepareParamsGet();
  165. $this->_iOwnerId = $aParams['owner_id'];
  166. $mixedAllowed = $this->isAllowedDelete($aEvent, true);
  167. if($mixedAllowed !== true)
  168. return echoJson(array('code' => 2, 'message' => strip_tags($mixedAllowed)));
  169. if(!$this->deleteEvent($aEvent))
  170. return echoJson(array('code' => 3));
  171. $this->_oDb->deleteCache(array('event_id' => $iId));
  172. echoJson(array(
  173. 'code' => 0,
  174. 'id' => $aEvent['id'],
  175. 'eval' => $this->_oConfig->getJsObjectView($aParams) . '.onDeletePost(oData)'
  176. ));
  177. }
  178. public function actionRepost()
  179. {
  180. $iAuthorId = $this->getUserId();
  181. $iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  182. $sType = bx_process_input(bx_get('type'), BX_DATA_TEXT);
  183. $sAction = bx_process_input(bx_get('action'), BX_DATA_TEXT);
  184. $iObjectId = bx_process_input(bx_get('object_id'), BX_DATA_INT);
  185. $aResult = $this->serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId);
  186. if(!empty($aResult) && is_array($aResult))
  187. return echoJson($aResult);
  188. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  189. $sCounter = $this->_oTemplate->getRepostCounter($aReposted);
  190. echoJson(array(
  191. 'code' => 0,
  192. 'message' => _t('_bx_timeline_txt_msg_success_repost'),
  193. 'count' => $aReposted['reposts'],
  194. 'countf' => (int)$aReposted['reposts'] > 0 ? $this->_oTemplate->getRepostCounterLabel($aReposted['reposts']) : '',
  195. 'counter' => $sCounter,
  196. 'disabled' => true
  197. ));
  198. }
  199. function actionGetPost()
  200. {
  201. $aParams = $this->_prepareParamsGet();
  202. $aParams['dynamic_mode'] = true;
  203. $this->_iOwnerId = $aParams['owner_id'];
  204. $sJsObject = '';
  205. if(bx_get('js_object') !== false)
  206. $sJsObject = bx_process_input(bx_get('js_object'));
  207. if(empty($sJsObject))
  208. $sJsObject = $this->_oConfig->getJsObject('post');
  209. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => bx_process_input(bx_get('id'), BX_DATA_INT)));
  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. /*
  217. $bAfpsLoading = (int)bx_get('afps_loading') === 1;
  218. if($bAfpsLoading && $this->_iOwnerId != $aEvent['owner_id'])
  219. return echoJson(array('message' => _t('_bx_timeline_txt_msg_posted')));
  220. */
  221. echoJson(array(
  222. 'id' => $aEvent['id'],
  223. 'name' => $aParams['name'],
  224. 'view' => $aParams['view'],
  225. 'type' => $aParams['type'],
  226. 'item' => $this->_oTemplate->getPost($aEvent, $aParams),
  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->getJsObjectView($aParams) . "._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. $aParams = $this->_prepareParamsGet();
  255. $this->_iOwnerId = $aParams['owner_id'];
  256. echoJson($this->getFormEdit($iId, array('dynamic_mode' => true), $aParams));
  257. }
  258. public function actionGetComments()
  259. {
  260. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  261. $sSystem = bx_process_input(bx_get('system'), BX_DATA_TEXT);
  262. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  263. $sComments = $this->_oTemplate->getComments($sSystem, $iId, array('dynamic_mode' => true));
  264. echoJson(array('content' => $sComments));
  265. }
  266. public function actionAddAttachLink()
  267. {
  268. $sUrl = bx_process_input(bx_get('url'));
  269. if(empty($sUrl))
  270. return echoJson(array());
  271. echoJson($this->addAttachLink(array(
  272. 'url' => $sUrl
  273. )));
  274. }
  275. public function actionDeleteAttachLink()
  276. {
  277. $iUserId = $this->getUserId();
  278. $iLinkId = bx_process_input(bx_get('id'), BX_DATA_INT);
  279. if(empty($iLinkId)) {
  280. echoJson(array());
  281. return;
  282. }
  283. $aLink = $this->_oDb->getUnusedLinks($iUserId, $iLinkId);
  284. if(empty($aLink) || !is_array($aLink)) {
  285. echoJson(array());
  286. return;
  287. }
  288. if(!empty($aLink['media_id']))
  289. BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'))->deleteFile($aLink['media_id']);
  290. $aResult = array();
  291. if($this->_oDb->deleteUnusedLinks($iUserId, $iLinkId))
  292. $aResult = array('code' => 0);
  293. else
  294. $aResult = array('code' => 1, 'message' => _t('_bx_timeline_form_post_input_link_err_delete'));
  295. echoJson($aResult);
  296. }
  297. public function actionGetAttachLinkForm()
  298. {
  299. echo $this->_oTemplate->getAttachLinkForm();
  300. }
  301. public function actionSubmitAttachLinkForm()
  302. {
  303. echoJson($this->getFormAttachLink());
  304. }
  305. public function actionGetRepostedBy()
  306. {
  307. $iRepostedId = bx_process_input(bx_get('id'), BX_DATA_INT);
  308. echo $this->_oTemplate->getRepostedBy($iRepostedId);
  309. }
  310. public function actionGetItemBrief()
  311. {
  312. echo BxDolPage::getObjectInstance($this->_oConfig->getObject('page_item_brief'), $this->_oTemplate)->getCodeDynamic();
  313. }
  314. public function actionGetJumpTo()
  315. {
  316. $aParams = $this->_prepareParamsGet();
  317. $this->_iOwnerId = $aParams['owner_id'];
  318. $sJsObjectView = $this->_oConfig->getJsObjectView($aParams);
  319. echoJson(array(
  320. 'content' => $this->_oTemplate->getJumpTo($aParams),
  321. 'eval' => $sJsObjectView . '.onGetJumpTo(oData)'
  322. ));
  323. }
  324. public function actionResumeLiveUpdate()
  325. {
  326. $aParams = $this->_prepareParamsGet();
  327. $sKey = $this->_oConfig->getLiveUpdateKey($aParams);
  328. bx_import('BxDolSession');
  329. BxDolSession::getInstance()->unsetValue($sKey);
  330. }
  331. public function actionPauseLiveUpdate()
  332. {
  333. $aParams = $this->_prepareParamsGet();
  334. $sKey = $this->_oConfig->getLiveUpdateKey($aParams);
  335. bx_import('BxDolSession');
  336. BxDolSession::getInstance()->setValue($sKey, 1);
  337. }
  338. function actionRss()
  339. {
  340. $CNF = &$this->_oConfig->CNF;
  341. $aArgs = func_get_args();
  342. $sType = array_shift($aArgs);
  343. $iOwnerId = 0;
  344. switch($sType) {
  345. case BX_BASE_MOD_NTFS_TYPE_OWNER:
  346. $iOwnerId = array_shift($aArgs);
  347. list($sUserName) = $this->getUserInfo($iOwnerId);
  348. $sRssCaption = _t('_bx_timeline_txt_rss_caption', $sUserName);
  349. $sRssLink = $this->_oConfig->getViewUrl($iOwnerId);
  350. break;
  351. case BX_BASE_MOD_NTFS_TYPE_PUBLIC:
  352. $sRssCaption = _t('_bx_timeline_page_title_view_home');
  353. $sRssLink = $this->_oConfig->getHomeViewUrl();
  354. break;
  355. }
  356. $aParams = $this->_prepareParams(array(
  357. 'view' => BX_TIMELINE_VIEW_DEFAULT,
  358. 'type' => $sType,
  359. 'owner_id' => $iOwnerId,
  360. 'start' => 0,
  361. 'per_page' => $this->_oConfig->getRssLength(),
  362. 'timeline' => 0,
  363. 'filter' => '',
  364. 'modules' => array()
  365. ));
  366. $aEvents = $this->_oDb->getEvents($aParams);
  367. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->getObject('privacy_view'));
  368. $aRssData = array();
  369. foreach($aEvents as $aEvent) {
  370. if(empty($aEvent['title']))
  371. continue;
  372. $iEventId = (int)$aEvent[$CNF['FIELD_ID']];
  373. $sEventFieldAuthor = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? 'owner_id' : 'object_id';
  374. if($oPrivacy) {
  375. $oPrivacy->setTableFieldAuthor($sEventFieldAuthor);
  376. if(!$oPrivacy->check($iEventId))
  377. continue;
  378. }
  379. $iOwner = $aEvent[$sEventFieldAuthor];
  380. $oOwner = BxDolProfile::getInstanceMagic($iOwner);
  381. $aRssData[$iEventId] = array(
  382. 'UnitID' => $iEventId,
  383. 'UnitTitle' => $aEvent['title'],
  384. 'UnitLink' => $this->_oConfig->getItemViewUrl($aEvent),
  385. 'UnitDesc' => bx_replace_markers($aEvent['description'], array(
  386. 'profile_name' => $oOwner->getDisplayName()
  387. )),
  388. 'UnitDateTimeUTS' => $aEvent['date'],
  389. );
  390. }
  391. $oRss = new BxDolRssFactory();
  392. header('Content-Type: application/xml; charset=utf-8');
  393. echo $oRss->GenRssByData($aRssData, $sRssCaption, $sRssLink);
  394. }
  395. /**
  396. * SERVICE METHODS
  397. */
  398. /**
  399. * @page service Service Calls
  400. * @section bx_timeline Timeline
  401. * @subsection bx_timeline-other Other
  402. * @subsubsection bx_timeline-get_create_post_form get_create_post_form
  403. *
  404. * @code bx_srv('bx_timeline', 'get_create_post_form', [...]); @endcode
  405. *
  406. * Get form code for add content. Is needed for United Post Form.
  407. *
  408. * @param $aParams optional array with parameters(display name, etc)
  409. * @return form code or error
  410. *
  411. * @see BxTimelineModule::serviceGetCreatePostForm
  412. */
  413. /**
  414. * @ref bx_timeline-get_create_post_form "get_create_post_form"
  415. */
  416. public function serviceGetCreatePostForm($aParams = array())
  417. {
  418. $aParams = array_merge($this->_aFormParams, $aParams);
  419. $bContext = $aParams['context_id'] !== false;
  420. $this->_iOwnerId = $bContext ? abs($aParams['context_id']) : 0;
  421. $oForm = $this->serviceGetObjectForm('add', $aParams);
  422. if(!$oForm)
  423. return '';
  424. $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  425. $aParams['form_display'] = 'form_display_post_add_public';
  426. if($bContext) {
  427. if($aParams['context_id'] < 0) {
  428. $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_OWNER;
  429. $aParams['form_display'] = 'form_display_post_add_profile';
  430. }
  431. else {
  432. $aParams['type'] = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  433. $aParams['form_display'] = 'form_display_post_add';
  434. }
  435. }
  436. if(!empty($aParams['display']))
  437. $aParams['form_display'] = $aParams['display'];
  438. $aResult = $this->getFormPost($aParams);
  439. if(!empty($aResult['form'])) {
  440. $bDynamicMode = isset($aParams['dynamic_mode']) && $aParams['dynamic_mode'];
  441. $sCode = '';
  442. $sCode .= $this->_oTemplate->getCssJs($bDynamicMode);
  443. $sCode .= $this->_oTemplate->getJsCodePost($this->_iOwnerId, $aParams);
  444. $sCode .= $aResult['form'];
  445. return $sCode;
  446. }
  447. if(!empty($aResult['message']))
  448. return $aResult['message'];
  449. return '';
  450. }
  451. /**
  452. * @page service Service Calls
  453. * @section bx_timeline Timeline
  454. * @subsection bx_timeline-other Other
  455. * @subsubsection bx_timeline-get_object_form get_object_form
  456. *
  457. * @code bx_srv('bx_timeline', 'get_object_form', [...]); @endcode
  458. *
  459. * Get form object for add, edit, view or delete the content.
  460. *
  461. * @param $sType 'add' is supported only
  462. * @param $aParams optional array with parameters(display name, etc)
  463. * @return form object or false on error
  464. *
  465. * @see BxTimelineModule::serviceGetObjectForm
  466. */
  467. /**
  468. * @ref bx_timeline-get_object_form "get_object_form"
  469. */
  470. public function serviceGetObjectForm ($sType, $aParams = array())
  471. {
  472. if(!in_array($sType, array('add')))
  473. return false;
  474. $bContext = $aParams['context_id'] !== false;
  475. if($bContext && ($oContextProfile = BxDolProfile::getInstance(abs($aParams['context_id']))) !== false)
  476. if($oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  477. return false;
  478. $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  479. $aParams['form_display'] = 'form_display_post_add_public';
  480. if($bContext) {
  481. if($aParams['context_id'] < 0) {
  482. $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_OWNER;
  483. $aParams['form_display'] = 'form_display_post_add_profile';
  484. }
  485. else {
  486. $aParams['type'] = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  487. $aParams['form_display'] = 'form_display_post_add';
  488. }
  489. }
  490. if(!empty($aParams['display']))
  491. $aParams['form_display'] = $aParams['display'];
  492. $oForm = $this->getFormPostObject($aParams);
  493. bx_alert('system', 'get_object_form', 0, 0, array(
  494. 'module' => $this->_oConfig->getName(),
  495. 'type' => $sType,
  496. 'params' => $aParams,
  497. 'form' => &$oForm
  498. ));
  499. return $oForm;
  500. }
  501. /**
  502. * @page service Service Calls
  503. * @section bx_timeline Timeline
  504. * @subsection get_timeline_post
  505. * @see BxTimelineModule::serviceGetTimelinePost
  506. *
  507. * Get Timeline post. It's needed for Timeline module.
  508. *
  509. * @param $aEvent timeline event array from Timeline module
  510. * @return array in special format which is needed specifically for Timeline module to display the data.
  511. */
  512. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  513. {
  514. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  515. if(empty($aContentInfo) || !is_array($aContentInfo))
  516. return false;
  517. $aEvent = array_merge($aEvent, array(
  518. 'owner_id' => $aContentInfo['owner_id'],
  519. 'object_privacy_view' => $aContentInfo['object_privacy_view']
  520. ));
  521. /*
  522. * Note. For 'Direct Timeline Posts' FIELD_OBJECT_ID contains post's author profile ID.
  523. */
  524. $this->_oConfig->CNF['FIELD_AUTHOR'] = $this->_oConfig->CNF['FIELD_OBJECT_ID'];
  525. return parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  526. }
  527. /**
  528. * @page service Service Calls
  529. * @section bx_timeline Timeline
  530. * @subsection get_timeline_post
  531. * @see BxTimelineModule::serviceGetTimelinePostAllowedView
  532. *
  533. * Check Timeline post's visibility. It's needed for Timeline module, when its events
  534. * are accessed and checked from outside. For example, when they are referenced
  535. * from Channels module.
  536. *
  537. * @param $aEvent timeline event array from Timeline module
  538. * @return mixed value: CHECK_ACTION_RESULT_ALLOWED or text of some error message.
  539. */
  540. public function serviceGetTimelinePostAllowedView($aEvent)
  541. {
  542. $CNF = &$this->_oConfig->CNF;
  543. $iOwnerId = (int)$aEvent[$CNF['FIELD_OWNER_ID']];
  544. if($iOwnerId == 0)
  545. return CHECK_ACTION_RESULT_ALLOWED;
  546. $oOwner = BxDolProfile::getInstance($iOwnerId);
  547. if(!$oOwner)
  548. return CHECK_ACTION_RESULT_ALLOWED;
  549. $sModule = $oOwner->getModule();
  550. $aOwnerInfo = BxDolService::call($sModule, 'get_info', array($oOwner->getContentId(), false));
  551. if(empty($aOwnerInfo) || !is_array($aOwnerInfo))
  552. return CHECK_ACTION_RESULT_ALLOWED;
  553. return BxDolService::call($sModule, 'check_allowed_view_for_profile', array($aOwnerInfo));
  554. }
  555. /**
  556. * @page service Service Calls
  557. * @section bx_timeline Timeline
  558. * @subsection bx_timeline-other Other
  559. * @subsubsection bx_timeline-get_author get_author
  560. *
  561. * @code bx_srv('bx_timeline', 'get_author', [...]); @endcode
  562. *
  563. * Get author ID from content info by content ID. Is used in "Content Info Objects" system.
  564. *
  565. * @param $iContentId integer value with content ID.
  566. * @return integer value with author ID.
  567. *
  568. * @see BxTimelineModule::serviceGetAuthor
  569. */
  570. /**
  571. * @ref bx_timeline-get_author "get_author"
  572. */
  573. public function serviceGetAuthor ($iContentId)
  574. {
  575. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  576. if(empty($aEvent) || !is_array($aEvent))
  577. return 0;
  578. return $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? (int)$aEvent['owner_id'] : (int)$aEvent['object_id'];
  579. }
  580. /**
  581. * @page service Service Calls
  582. * @section bx_timeline Timeline
  583. * @subsection bx_timeline-other Other
  584. * @subsubsection bx_timeline-get_date_changed get_date_changed
  585. *
  586. * @code bx_srv('bx_timeline', 'get_date_changed', [...]); @endcode
  587. *
  588. * Get date when the content was changed last time. Is used in "Content Info Objects" system.
  589. * Note. In case of Timeline event 0 is returned everytime.
  590. *
  591. * @param $iContentId integer value with content ID.
  592. * @return integer value with changing date.
  593. *
  594. * @see BxTimelineModule::serviceGetDateChanged
  595. */
  596. /**
  597. * @ref bx_timeline-get_date_changed "get_date_changed"
  598. */
  599. public function serviceGetDateChanged ($iContentId)
  600. {
  601. return 0;
  602. }
  603. /**
  604. * @page service Service Calls
  605. * @section bx_timeline Timeline
  606. * @subsection bx_timeline-other Other
  607. * @subsubsection bx_timeline-get_link get_link
  608. *
  609. * @code bx_srv('bx_timeline', 'get_link', [...]); @endcode
  610. *
  611. * Get content view page link. Is used in "Content Info Objects" system.
  612. *
  613. * @param $iContentId integer value with content ID.
  614. * @return string value with view page link.
  615. *
  616. * @see BxTimelineModule::serviceGetLink
  617. */
  618. /**
  619. * @ref bx_timeline-get_link "get_link"
  620. */
  621. public function serviceGetLink ($iContentId)
  622. {
  623. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  624. if(empty($aEvent) || !is_array($aEvent))
  625. return '';
  626. return $this->_oConfig->getItemViewUrl($aEvent);
  627. }
  628. /**
  629. * @page service Service Calls
  630. * @section bx_timeline Timeline
  631. * @subsection bx_timeline-other Other
  632. * @subsubsection bx_timeline-get_thumb get_thumb
  633. *
  634. * @code bx_srv('bx_timeline', 'get_thumb', [...]); @endcode
  635. *
  636. * Get content thumbnail link. Is used in "Content Info Objects" system.
  637. * Note. In case of Timeline event an empty string is returned everytime.
  638. *
  639. * @param $iContentId integer value with content ID.
  640. * @param $sTranscoder (optional) string value with transcoder name which should be applied to thumbnail image.
  641. * @return string value with thumbnail link.
  642. *
  643. * @see BxTimelineModule::serviceGetThumb
  644. */
  645. /**
  646. * @ref bx_timeline-get_thumb "get_thumb"
  647. */
  648. public function serviceGetThumb ($iContentId, $sTranscoder = '')
  649. {
  650. return '';
  651. }
  652. /**
  653. * @page service Service Calls
  654. * @section bx_timeline Timeline
  655. * @subsection bx_timeline-other Other
  656. * @subsubsection bx_timeline-get_info get_info
  657. *
  658. * @code bx_srv('bx_timeline', 'get_info', [...]); @endcode
  659. *
  660. * Get content info by content ID. Is used in "Content Info Objects" system.
  661. *
  662. * @param $iContentId integer value with content ID.
  663. * @param $bSearchableFieldsOnly (optional) boolean value determining all info or "searchable fields" only will be returned.
  664. * @return an array with content info. Empty array is returned if something is wrong.
  665. *
  666. * @see BxTimelineModule::serviceGetInfo
  667. */
  668. /**
  669. * @ref bx_timeline-get_info "get_info"
  670. */
  671. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  672. {
  673. $aContentInfo = $this->_oDb->getEvents(array(
  674. 'browse' => 'id',
  675. 'value' => $iContentId)
  676. );
  677. return BxDolContentInfo::formatFields($aContentInfo);
  678. }
  679. /**
  680. * @page service Service Calls
  681. * @section bx_timeline Timeline
  682. * @subsection bx_timeline-other Other
  683. * @subsubsection bx_timeline-get_search_result_unit get_search_result_unit
  684. *
  685. * @code bx_srv('bx_timeline', 'get_search_result_unit', [...]); @endcode
  686. *
  687. * Get search result unit by content ID. Is used in "Content Info Objects" system.
  688. *
  689. * @param $iContentId integer value with content ID.
  690. * @param $sUnitTemplate (optional) string value with template name.
  691. * @return HTML string with search result unit. Empty string is returned if something is wrong.
  692. *
  693. * @see BxTimelineModule::serviceGetSearchResultUnit
  694. */
  695. /**
  696. * @ref bx_timeline-get_search_result_unit "get_search_result_unit"
  697. */
  698. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  699. {
  700. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  701. if(empty($aEvent) || !is_array($aEvent))
  702. return '';
  703. if(empty($sUnitTemplate))
  704. $sUnitTemplate = 'unit.html';
  705. return $this->_oTemplate->unit($aEvent, true, $sUnitTemplate);
  706. }
  707. /**
  708. * @page service Service Calls
  709. * @section bx_timeline Timeline
  710. * @subsection bx_timeline-page_blocks Page Blocks
  711. * @subsubsection bx_timeline-get_block_post get_block_post
  712. *
  713. * @code bx_srv('bx_timeline', 'get_block_post', [...]); @endcode
  714. *
  715. * Get Post block for a separate page.
  716. *
  717. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  718. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  719. *
  720. * @see BxTimelineModule::serviceGetBlockPost
  721. */
  722. /**
  723. * @ref bx_timeline-get_block_post "get_block_post"
  724. */
  725. public function serviceGetBlockPost($iProfileId = 0)
  726. {
  727. if(empty($iProfileId) && bx_get('profile_id') !== false)
  728. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  729. if(empty($iProfileId) && isLogged())
  730. $iProfileId = bx_get_logged_profile_id();
  731. if(!$iProfileId)
  732. return array();
  733. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  734. return $this->_getBlockPost($iProfileId, array(
  735. 'type' => $sType,
  736. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  737. ));
  738. }
  739. /**
  740. * @page service Service Calls
  741. * @section bx_timeline Timeline
  742. * @subsection bx_timeline-page_blocks Page Blocks
  743. * @subsubsection bx_timeline-get_block_post_profile get_block_post_profile
  744. *
  745. * @code bx_srv('bx_timeline', 'get_block_post_profile', [...]); @endcode
  746. *
  747. * Get Post block for the Profile page.
  748. *
  749. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  750. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  751. * @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.
  752. *
  753. * @see BxTimelineModule::serviceGetBlockPostProfile
  754. */
  755. /**
  756. * @ref bx_timeline-get_block_post_profile "get_block_post_profile"
  757. */
  758. public function serviceGetBlockPostProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0)
  759. {
  760. if(empty($sProfileModule))
  761. return array();
  762. if(empty($iProfileContentId) && bx_get('id') !== false)
  763. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  764. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  765. if(empty($oProfile))
  766. return array();
  767. $iProfileId = $oProfile->id();
  768. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  769. return $this->_getBlockPost($iProfileId, array(
  770. 'type' => $sType,
  771. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  772. ));
  773. }
  774. /**
  775. * @page service Service Calls
  776. * @section bx_timeline Timeline
  777. * @subsection bx_timeline-page_blocks Page Blocks
  778. * @subsubsection bx_timeline-get_block_post_home get_block_post_home
  779. *
  780. * @code bx_srv('bx_timeline', 'get_block_post_home', [...]); @endcode
  781. *
  782. * Get Post block for site's Home page.
  783. *
  784. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  785. *
  786. * @see BxTimelineModule::serviceGetBlockPostHome
  787. */
  788. /**
  789. * @ref bx_timeline-get_block_post_home "get_block_post_home"
  790. */
  791. public function serviceGetBlockPostHome()
  792. {
  793. $iProfileId = 0;
  794. $sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  795. return $this->_getBlockPost($iProfileId, array(
  796. 'type' => $sType,
  797. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  798. ));
  799. }
  800. /**
  801. * @page service Service Calls
  802. * @section bx_timeline Timeline
  803. * @subsection bx_timeline-page_blocks Page Blocks
  804. * @subsubsection bx_timeline-get_block_post_account get_block_post_account
  805. *
  806. * @code bx_srv('bx_timeline', 'get_block_post_account', [...]); @endcode
  807. *
  808. * Get Post block for the Dashboard page.
  809. *
  810. * @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.
  811. *
  812. * @see BxTimelineModule::serviceGetBlockPostAccount
  813. */
  814. /**
  815. * @ref bx_timeline-get_block_post_account "get_block_post_account"
  816. */
  817. public function serviceGetBlockPostAccount()
  818. {
  819. if(!isLogged())
  820. return '';
  821. $iProfileId = $this->getProfileId();
  822. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  823. return $this->_getBlockPost($iProfileId, array(
  824. 'type' => $sType,
  825. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  826. ));
  827. }
  828. /**
  829. * @page service Service Calls
  830. * @section bx_timeline Timeline
  831. * @subsection bx_timeline-page_blocks Page Blocks
  832. * @subsubsection bx_timeline-get_block_view get_block_view
  833. *
  834. * @code bx_srv('bx_timeline', 'get_block_view', [...]); @endcode
  835. *
  836. * Get Timeline View block for a separate page.
  837. *
  838. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  839. * @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.
  840. *
  841. * @see BxTimelineModule::serviceGetBlockView
  842. */
  843. /**
  844. * @ref bx_timeline-get_block_view "get_block_view"
  845. */
  846. public function serviceGetBlockView($iProfileId = 0)
  847. {
  848. return $this->_serviceGetBlockView($iProfileId, array(
  849. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  850. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  851. 'start' => -1,
  852. 'per_page' => -1,
  853. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  854. 'timeline' => -1,
  855. 'filter' => '',
  856. 'modules' => array()
  857. ));
  858. }
  859. /**
  860. * @page service Service Calls
  861. * @section bx_timeline Timeline
  862. * @subsection bx_timeline-page_blocks Page Blocks
  863. * @subsubsection bx_timeline-get_block_view_outline get_block_view_outline
  864. *
  865. * @code bx_srv('bx_timeline', 'get_block_view_outline', [...]); @endcode
  866. *
  867. * Get Outline View block for a separate page.
  868. *
  869. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  870. * @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.
  871. *
  872. * @see BxTimelineModule::serviceGetBlockViewOutline
  873. */
  874. /**
  875. * @ref bx_timeline-get_block_view_outline "get_block_view_outline"
  876. */
  877. public function serviceGetBlockViewOutline($iProfileId = 0)
  878. {
  879. return $this->_serviceGetBlockView($iProfileId, array(
  880. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  881. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  882. 'start' => -1,
  883. 'per_page' => -1,
  884. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  885. 'timeline' => -1,
  886. 'filter' => '',
  887. 'modules' => array()
  888. ));
  889. }
  890. /**
  891. * @page service Service Calls
  892. * @section bx_timeline Timeline
  893. * @subsection bx_timeline-page_blocks Page Blocks
  894. * @subsubsection bx_timeline-get_block_view_profile get_block_view_profile
  895. *
  896. * @code bx_srv('bx_timeline', 'get_block_view_profile', [...]); @endcode
  897. *
  898. * Get Timeline View block for the Profile page.
  899. *
  900. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  901. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  902. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  903. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  904. * @param $sFilter (optional) string value with filter name.
  905. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  906. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  907. * @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.
  908. *
  909. * @see BxTimelineModule::serviceGetBlockViewProfile
  910. */
  911. /**
  912. * @ref bx_timeline-get_block_view_profile "get_block_view_profile"
  913. */
  914. public function serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  915. {
  916. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, array(
  917. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  918. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  919. 'start' => $iStart,
  920. 'per_page' => $iPerPage,
  921. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  922. 'timeline' => $iTimeline,
  923. 'filter' => $sFilter,
  924. 'modules' => $aModules
  925. ));
  926. }
  927. /**
  928. * @page service Service Calls
  929. * @section bx_timeline Timeline
  930. * @subsection bx_timeline-page_blocks Page Blocks
  931. * @subsubsection bx_timeline-get_block_view_profile_outline get_block_view_profile_outline
  932. *
  933. * @code bx_srv('bx_timeline', 'get_block_view_profile_outline', [...]); @endcode
  934. *
  935. * Get Outline View block for the Profile page.
  936. *
  937. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  938. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  939. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  940. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  941. * @param $sFilter (optional) string value with filter name.
  942. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  943. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  944. * @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.
  945. *
  946. * @see BxTimelineModule::serviceGetBlockViewProfileOutline
  947. */
  948. /**
  949. * @ref bx_timeline-get_block_view_profile_outline "get_block_view_profile_outline"
  950. */
  951. public function serviceGetBlockViewProfileOutline($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  952. {
  953. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, array(
  954. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  955. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  956. 'start' => $iStart,
  957. 'per_page' => $iPerPage,
  958. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  959. 'timeline' => $iTimeline,
  960. 'filter' => $sFilter,
  961. 'modules' => $aModules
  962. ));
  963. }
  964. /**
  965. * @page service Service Calls
  966. * @section bx_timeline Timeline
  967. * @subsection bx_timeline-page_blocks Page Blocks
  968. * @subsubsection bx_timeline-get_block_view_home get_block_view_home
  969. *
  970. * @code bx_srv('bx_timeline', 'get_block_view_home', [...]); @endcode
  971. *
  972. * Get Timeline View block for site's Home page.
  973. *
  974. * @param $iProfileId (optional) profile ID. 0 should be used here.
  975. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  976. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  977. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  978. * @param $sFilter (optional) string value with filter name.
  979. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  980. * @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.
  981. *
  982. * @see BxTimelineModule::serviceGetBlockViewHome
  983. */
  984. /**
  985. * @ref bx_timeline-get_block_view_home "get_block_view_home"
  986. */
  987. public function serviceGetBlockViewHome($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  988. {
  989. return $this->_serviceGetBlockViewHome(array(
  990. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  991. 'type' => BX_BASE_MOD_NTFS_TYPE_PUBLIC,
  992. 'owner_id' => $iProfileId,
  993. 'start' => $iStart,
  994. 'per_page' => $iPerPage,
  995. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  996. 'timeline' => $iTimeline,
  997. 'filter' => $sFilter,
  998. 'modules' => $aModules
  999. ));
  1000. }
  1001. /**
  1002. * @page service Service Calls
  1003. * @section bx_timeline Timeline
  1004. * @subsection bx_timeline-page_blocks Page Blocks
  1005. * @subsubsection bx_timeline-get_block_view_home_outline get_block_view_home_outline
  1006. *
  1007. * @code bx_srv('bx_timeline', 'get_block_view_home_outline', [...]); @endcode
  1008. *
  1009. * Get Outline View block for site's Home page.
  1010. *
  1011. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1012. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1013. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1014. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1015. * @param $sFilter (optional) string value with filter name.
  1016. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1017. * @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.
  1018. *
  1019. * @see BxTimelineModule::serviceGetBlockViewHomeOutline
  1020. */
  1021. /**
  1022. * @ref bx_timeline-get_block_view_home_outline "get_block_view_home_outline"
  1023. */
  1024. public function serviceGetBlockViewHomeOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1025. {
  1026. return $this->_serviceGetBlockViewHome(array(
  1027. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1028. 'type' => BX_BASE_MOD_NTFS_TYPE_PUBLIC,
  1029. 'owner_id' => $iProfileId,
  1030. 'start' => $iStart,
  1031. 'per_page' => $iPerPage,
  1032. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  1033. 'timeline' => $iTimeline,
  1034. 'filter' => $sFilter,
  1035. 'modules' => $aModules
  1036. ));
  1037. }
  1038. /**
  1039. * @page service Service Calls
  1040. * @section bx_timeline Timeline
  1041. * @subsection bx_timeline-page_blocks Page Blocks
  1042. * @subsubsection bx_timeline-get_block_view_hot get_block_view_hot
  1043. *
  1044. * @code bx_srv('bx_timeline', 'get_block_view_hot', [...]); @endcode
  1045. *
  1046. * Get Timeline View block with Hot public events.
  1047. *
  1048. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1049. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1050. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1051. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1052. * @param $sFilter (optional) string value with filter name.
  1053. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1054. * @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.
  1055. *
  1056. * @see BxTimelineModule::serviceGetBlockViewHot
  1057. */
  1058. /**
  1059. * @ref bx_timeline-get_block_view_hot "get_block_view_hot"
  1060. */
  1061. public function serviceGetBlockViewHot($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1062. {
  1063. return $this->_serviceGetBlockViewHot(array(
  1064. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1065. 'type' => BX_TIMELINE_TYPE_HOT,
  1066. 'owner_id' => $iProfileId,
  1067. 'start' => $iStart,
  1068. 'per_page' => $iPerPage,
  1069. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  1070. 'timeline' => $iTimeline,
  1071. 'filter' => $sFilter,
  1072. 'modules' => $aModules
  1073. ));
  1074. }
  1075. /**
  1076. * @page service Service Calls
  1077. * @section bx_timeline Timeline
  1078. * @subsection bx_timeline-page_blocks Page Blocks
  1079. * @subsubsection bx_timeline-get_block_view_hot_outline get_block_view_hot_outline
  1080. *
  1081. * @code bx_srv('bx_timeline', 'get_block_view_hot_outline', [...]); @endcode
  1082. *
  1083. * Get Outline View block with Hot public events.
  1084. *
  1085. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1086. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1087. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1088. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1089. * @param $sFilter (optional) string value with filter name.
  1090. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1091. * @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.
  1092. *
  1093. * @see BxTimelineModule::serviceGetBlockViewHotOutline
  1094. */
  1095. /**
  1096. * @ref bx_timeline-get_block_view_hot_outline "get_block_view_hot_outline"
  1097. */
  1098. public function serviceGetBlockViewHotOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1099. {
  1100. return $this->_serviceGetBlockViewHot(array(
  1101. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1102. 'type' => BX_TIMELINE_TYPE_HOT,
  1103. 'owner_id' => $iProfileId,
  1104. 'start' => $iStart,
  1105. 'per_page' => $iPerPage,
  1106. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  1107. 'timeline' => $iTimeline,
  1108. 'filter' => $sFilter,
  1109. 'modules' => $aModules
  1110. ));
  1111. }
  1112. /**
  1113. * @page service Service Calls
  1114. * @section bx_timeline Timeline
  1115. * @subsection bx_timeline-page_blocks Page Blocks
  1116. * @subsubsection bx_timeline-get_block_view_account get_block_view_account
  1117. *
  1118. * @code bx_srv('bx_timeline', 'get_block_view_account', [...]); @endcode
  1119. *
  1120. * Get Timeline View block for the Dashboard page.
  1121. *
  1122. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1123. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1124. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1125. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1126. * @param $sFilter (optional) string value with filter name.
  1127. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1128. * @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.
  1129. *
  1130. * @see BxTimelineModule::serviceGetBlockViewAccount
  1131. */
  1132. /**
  1133. * @ref bx_timeline-get_block_view_account "get_block_view_account"
  1134. */
  1135. public function serviceGetBlockViewAccount($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1136. {
  1137. if(!isLogged())
  1138. return '';
  1139. return $this->_serviceGetBlockViewByType(array(
  1140. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1141. 'type' => BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS,
  1142. 'owner_id' => $iProfileId,
  1143. 'start' => $iStart,
  1144. 'per_page' => $iPerPage,
  1145. 'per_page_default' => $this->_oConfig->getPerPage('account'),
  1146. 'timeline' => $iTimeline,
  1147. 'filter' => $sFilter,
  1148. 'modules' => $aModules
  1149. ));
  1150. }
  1151. /**
  1152. * @page service Service Calls
  1153. * @section bx_timeline Timeline
  1154. * @subsection bx_timeline-page_blocks Page Blocks
  1155. * @subsubsection bx_timeline-get_block_view_account_outline get_block_view_account_outline
  1156. *
  1157. * @code bx_srv('bx_timeline', 'get_block_view_account_outline', [...]); @endcode
  1158. *
  1159. * Get Outline View block for the Dashboard page.
  1160. *
  1161. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1162. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1163. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1164. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1165. * @param $sFilter (optional) string value with filter name.
  1166. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1167. * @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.
  1168. *
  1169. * @see BxTimelineModule::serviceGetBlockViewAccountOutline
  1170. */
  1171. /**
  1172. * @ref bx_timeline-get_block_view_account_outline "get_block_view_account_outline"
  1173. */
  1174. public function serviceGetBlockViewAccountOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1175. {
  1176. if(!isLogged())
  1177. return '';
  1178. return $this->_serviceGetBlockViewByType(array(
  1179. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1180. 'type' => BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS,
  1181. 'owner_id' => $iProfileId,
  1182. 'start' => $iStart,
  1183. 'per_page' => $iPerPage,
  1184. 'per_page_default' => $this->_oConfig->getPerPage('account'),
  1185. 'timeline' => $iTimeline,
  1186. 'filter' => $sFilter,
  1187. 'modules' => $aModules
  1188. ));
  1189. }
  1190. /**
  1191. * @page service Service Calls
  1192. * @section bx_timeline Timeline
  1193. * @subsection bx_timeline-page_blocks Page Blocks
  1194. * @subsubsection bx_timeline-get_block_view_custom get_block_view_custom
  1195. *
  1196. * @code bx_srv('bx_timeline', 'get_block_view_custom', [...]); @endcode
  1197. *
  1198. * Get custom Timeline View block.
  1199. *
  1200. * @param $aParams (optional) an array with block parameneters.
  1201. * @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.
  1202. *
  1203. * @see BxTimelineModule::serviceGetBlockViewCustom
  1204. */
  1205. /**
  1206. * @ref bx_timeline-get_block_view_custom "get_block_view_custom"
  1207. */
  1208. public function serviceGetBlockViewCustom($aParams = array())
  1209. {
  1210. return $this->_serviceGetBlockViewByType($aParams);
  1211. }
  1212. /**
  1213. * @page service Service Calls
  1214. * @section bx_timeline Timeline
  1215. * @subsection bx_timeline-page_blocks Page Blocks
  1216. * @subsubsection bx_timeline-get_block_item get_block_item
  1217. *
  1218. * @code bx_srv('bx_timeline', 'get_block_item', [...]); @endcode
  1219. *
  1220. * Get View Item block.
  1221. *
  1222. * @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.
  1223. *
  1224. * @see BxTimelineModule::serviceGetBlockItem
  1225. */
  1226. /**
  1227. * @ref bx_timeline-get_block_item "get_block_item"
  1228. */
  1229. public function serviceGetBlockItem()
  1230. {
  1231. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1232. if(!$iItemId)
  1233. return array();
  1234. $aParams = array(
  1235. 'view' => BX_TIMELINE_VIEW_ITEM,
  1236. 'type' => BX_TIMELINE_TYPE_ITEM
  1237. );
  1238. $aParams = $this->_prepareParams($aParams);
  1239. return $this->_oTemplate->getItemBlock($iItemId, $aParams);
  1240. }
  1241. public function serviceGetBlockItemContent()
  1242. {
  1243. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1244. $sMode = bx_process_input(bx_get('mode'));
  1245. if(!$iItemId || !$sMode)
  1246. return '';
  1247. return $this->_oTemplate->getItemBlockContent($iItemId, $sMode);
  1248. }
  1249. public function serviceGetBlockItemInfo()
  1250. {
  1251. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1252. if(!$iItemId)
  1253. return '';
  1254. return $this->_oTemplate->getItemBlockInfo($iItemId);
  1255. }
  1256. public function serviceGetBlockItemComments()
  1257. {
  1258. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1259. if(!$iItemId)
  1260. return '';
  1261. return $this->_oTemplate->getItemBlockComments($iItemId);
  1262. }
  1263. /**
  1264. * @page service Service Calls
  1265. * @section bx_timeline Timeline
  1266. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1267. * @subsubsection bx_timeline-get_notifications_data get_notifications_data
  1268. *
  1269. * @code bx_srv('bx_timeline', 'get_notifications_data', [...]); @endcode
  1270. *
  1271. * Data for Notifications module.
  1272. *
  1273. * @return an array with special format.
  1274. *
  1275. * @see BxTimelineModule::serviceGetNotificationsData
  1276. */
  1277. /**
  1278. * @ref bx_timeline-get_notifications_data "get_notifications_data"
  1279. */
  1280. public function serviceGetNotificationsData()
  1281. {
  1282. $sModule = $this->_aModule['name'];
  1283. return array(
  1284. 'handlers' => array(
  1285. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'post_common', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module'),
  1286. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete'),
  1287. array('group' => $sModule . '_repost', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'repost', 'module_name' => $sModule, 'module_method' => 'get_notifications_repost', 'module_class' => 'Module'),
  1288. array('group' => $sModule . '_repost', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete_repost'),
  1289. array('group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment', 'module_class' => 'Module'),
  1290. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  1291. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'),
  1292. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  1293. array('group' => $sModule . '_reaction', 'type' => 'insert', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_reaction', 'module_class' => 'Module'),
  1294. array('group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote'),
  1295. array('group' => $sModule . '_score_up', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteUp', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_up', 'module_class' => 'Module'),
  1296. array('group' => $sModule . '_score_down', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteDown', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_down', 'module_class' => 'Module'),
  1297. ),
  1298. 'settings' => array(
  1299. array('group' => 'content', 'unit' => $sModule, 'action' => 'post_common', 'types' => array('personal', 'follow_member', 'follow_context')),
  1300. array('group' => 'content', 'unit' => $sModule, 'action' => 'repost', 'types' => array('follow_member', 'follow_context')),
  1301. array('group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => array('personal', 'follow_member', 'follow_context')),
  1302. array('group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1303. array('group' => 'vote', 'unit' => $sModule . '_reactions', 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1304. array('group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => array('personal', 'follow_member', 'follow_context')),
  1305. array('group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => array('personal', 'follow_member', 'follow_context'))
  1306. ),
  1307. 'alerts' => array(
  1308. array('unit' => $sModule, 'action' => 'post_common'),
  1309. array('unit' => $sModule, 'action' => 'delete'),
  1310. array('unit' => $sModule, 'action' => 'repost'),
  1311. array('unit' => $sModule, 'action' => 'delete_repost'),
  1312. array('unit' => $sModule, 'action' => 'commentPost'),
  1313. array('unit' => $sModule, 'action' => 'commentRemoved'),
  1314. array('unit' => $sModule, 'action' => 'doVote'),
  1315. array('unit' => $sModule, 'action' => 'undoVote'),
  1316. array('unit' => $sModule . '_reactions', 'action' => 'doVote'),
  1317. array('unit' => $sModule . '_reactions', 'action' => 'undoVote'),
  1318. array('unit' => $sModule, 'action' => 'doVoteUp'),
  1319. array('unit' => $sModule, 'action' => 'doVoteDown'),
  1320. )
  1321. );
  1322. }
  1323. /**
  1324. * @page service Service Calls
  1325. * @section bx_timeline Timeline
  1326. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1327. * @subsubsection bx_timeline-get_notifications_repost get_notifications_repost
  1328. *
  1329. * @code bx_srv('bx_timeline', 'get_notifications_repost', [...]); @endcode
  1330. *
  1331. * Get data for Repost event to display in Notifications module.
  1332. *
  1333. * @param $aEvent an array with event description.
  1334. * @return an array with special format.
  1335. *
  1336. * @see BxTimelineModule::serviceGetNotificationsRepost
  1337. */
  1338. /**
  1339. * @ref bx_timeline-get_notifications_repost "get_notifications_repost"
  1340. */
  1341. public function serviceGetNotificationsRepost($aEvent)
  1342. {
  1343. $aResult = $this->serviceGetNotificationsPost($aEvent);
  1344. $aResult['lang_key'] = '_bx_timeline_txt_object_reposted';
  1345. return $aResult;
  1346. }
  1347. /**
  1348. * @page service Service Calls
  1349. * @section bx_timeline Timeline
  1350. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1351. * @subsubsection bx_timeline-get_notifications_post get_notifications_post
  1352. *
  1353. * @code bx_srv('bx_timeline', 'get_notifications_post', [...]); @endcode
  1354. *
  1355. * Get data for Post event to display in Notifications module.
  1356. *
  1357. * @param $aEvent an array with event description.
  1358. * @return an array with special format.
  1359. *
  1360. * @see BxTimelineModule::serviceGetNotificationsPost
  1361. */
  1362. /**
  1363. * @ref bx_timeline-get_notifications_post "get_notifications_post"
  1364. */
  1365. public function serviceGetNotificationsPost($aEvent)
  1366. {
  1367. $CNF = &$this->_oConfig->CNF;
  1368. $iContent = (int)$aEvent['object_id'];
  1369. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1370. if(empty($aContent) || !is_array($aContent))
  1371. return array();
  1372. if($this->_oConfig->isSystem($aContent['type'], $aContent['action']))
  1373. $iEntryAuthor = (int)$aContent['owner_id'];
  1374. else
  1375. $iEntryAuthor = (int)$aContent['object_id'];
  1376. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1377. return array(
  1378. 'entry_sample' => $CNF['T']['txt_sample_single_ext'],
  1379. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1380. 'entry_caption' => $sEntryCaption,
  1381. 'entry_author' => $iEntryAuthor,
  1382. 'lang_key' => '' //may be empty or not specified. In this case the default one from Notification module will be used.
  1383. );
  1384. }
  1385. /**
  1386. * @page service Service Calls
  1387. * @section bx_timeline Timeline
  1388. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1389. * @subsubsection bx_timeline-get_notifications_comment get_notifications_comment
  1390. *
  1391. * @code bx_srv('bx_timeline', 'get_notifications_comment', [...]); @endcode
  1392. *
  1393. * Get data for Post Comment event to display in Notifications module.
  1394. *
  1395. * @param $aEvent an array with event description.
  1396. * @return an array with special format.
  1397. *
  1398. * @see BxTimelineModule::serviceGetNotificationsComment
  1399. */
  1400. /**
  1401. * @ref bx_timeline-get_notifications_comment "get_notifications_comment"
  1402. */
  1403. public function serviceGetNotificationsComment($aEvent)
  1404. {
  1405. $CNF = &$this->_oConfig->CNF;
  1406. $iContent = (int)$aEvent['object_id'];
  1407. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1408. if(empty($aContent) || !is_array($aContent))
  1409. return array();
  1410. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContent);
  1411. if(!$oComment || !$oComment->isEnabled())
  1412. return array();
  1413. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1414. return array(
  1415. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1416. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1417. 'entry_caption' => $sEntryCaption,
  1418. 'entry_author' => $aContent['owner_id'],
  1419. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  1420. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  1421. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1422. );
  1423. }
  1424. /**
  1425. * @page service Service Calls
  1426. * @section bx_timeline Timeline
  1427. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1428. * @subsubsection bx_timeline-get_notifications_vote get_notifications_vote
  1429. *
  1430. * @code bx_srv('bx_timeline', 'get_notifications_vote', [...]); @endcode
  1431. *
  1432. * Get data for Vote event to display in Notifications module.
  1433. *
  1434. * @param $aEvent an array with event description.
  1435. * @return an array with special format.
  1436. *
  1437. * @see BxTimelineModule::serviceGetNotificationsVote
  1438. */
  1439. /**
  1440. * @ref bx_timeline-get_notifications_vote "get_notifications_vote"
  1441. */
  1442. public function serviceGetNotificationsVote($aEvent)
  1443. {
  1444. $CNF = &$this->_oConfig->CNF;
  1445. $iContent = (int)$aEvent['object_id'];
  1446. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1447. if(empty($aContent) || !is_array($aContent))
  1448. return array();
  1449. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContent);
  1450. if(!$oVote || !$oVote->isEnabled())
  1451. return array();
  1452. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1453. return array(
  1454. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1455. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1456. 'entry_caption' => $sEntryCaption,
  1457. 'entry_author' => $aContent['owner_id'],
  1458. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  1459. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1460. );
  1461. }
  1462. /**
  1463. * Entry post vote for Notifications module
  1464. */
  1465. public function serviceGetNotificationsReaction($aEvent)
  1466. {
  1467. $CNF = &$this->_oConfig->CNF;
  1468. $iContent = (int)$aEvent['object_id'];
  1469. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1470. if(empty($aContent) || !is_array($aContent))
  1471. return array();
  1472. $oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $iContent);
  1473. if(!$oReaction || !$oReaction->isEnabled())
  1474. return array();
  1475. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  1476. if(empty($aSubentry) || !is_array($aSubentry))
  1477. return array();
  1478. $aSubentrySampleParams = array();
  1479. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  1480. if(!empty($aReaction['title']))
  1481. $aSubentrySampleParams[] = $aReaction['title'];
  1482. else
  1483. $aSubentrySampleParams[] = '_undefined';
  1484. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1485. return array(
  1486. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1487. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1488. 'entry_caption' => $sEntryCaption,
  1489. 'entry_author' => $aContent['owner_id'],
  1490. 'subentry_sample' => $CNF['T']['txt_sample_reaction_single'],
  1491. 'subentry_sample_params' => $aSubentrySampleParams,
  1492. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1493. );
  1494. }
  1495. /**
  1496. * @page service Service Calls
  1497. * @section bx_timeline Timeline
  1498. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1499. * @subsubsection bx_timeline-get_notifications_score_up get_notifications_score_up
  1500. *
  1501. * @code bx_srv('bx_timeline', 'get_notifications_score_up', [...]); @endcode
  1502. *
  1503. * Get data for Score Up Vote event to display in Notifications module.
  1504. *
  1505. * @param $aEvent an array with event description.
  1506. * @return an array with special format.
  1507. *
  1508. * @see BxTimelineModule::serviceGetNotificationsScoreUp
  1509. */
  1510. /**
  1511. * @ref bx_timeline-get_notifications_score_up "get_notifications_score_up"
  1512. */
  1513. public function serviceGetNotificationsScoreUp($aEvent)
  1514. {
  1515. return $this->_serviceGetNotificationsScore('up', $aEvent);
  1516. }
  1517. /**
  1518. * @page service Service Calls
  1519. * @section bx_timeline Timeline
  1520. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1521. * @subsubsection bx_timeline-get_notifications_score_down get_notifications_score_down
  1522. *
  1523. * @code bx_srv('bx_timeline', 'get_notifications_score_down', [...]); @endcode
  1524. *
  1525. * Get data for Score Down Vote event to display in Notifications module.
  1526. *
  1527. * @param $aEvent an array with event description.
  1528. * @return an array with special format.
  1529. *
  1530. * @see BxTimelineModule::serviceGetNotificationsScoreDown
  1531. */
  1532. /**
  1533. * @ref bx_timeline-get_notifications_score_down "get_notifications_score_down"
  1534. */
  1535. public function serviceGetNotificationsScoreDown($aEvent)
  1536. {
  1537. return $this->_serviceGetNotificationsScore('down', $aEvent);
  1538. }
  1539. protected function _serviceGetNotificationsScore($sType, $aEvent)
  1540. {
  1541. $CNF = &$this->_oConfig->CNF;
  1542. $iContent = (int)$aEvent['object_id'];
  1543. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1544. if(empty($aContent) || !is_array($aContent))
  1545. return array();
  1546. $oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContent);
  1547. if(!$oScore || !$oScore->isEnabled())
  1548. return array();
  1549. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1550. return array(
  1551. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1552. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1553. 'entry_caption' => $sEntryCaption,
  1554. 'entry_author' => $aContent['owner_id'],
  1555. 'subentry_sample' => $CNF['T']['txt_sample_score_' . $sType . '_single'],
  1556. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1557. );
  1558. }
  1559. /**
  1560. * @page service Service Calls
  1561. * @section bx_timeline Timeline
  1562. * @subsection bx_timeline-repost Repost
  1563. * @subsubsection bx_timeline-get_repost_element_block get_repost_element_block
  1564. *
  1565. * @code bx_srv('bx_timeline', 'get_repost_element_block', [...]); @endcode
  1566. *
  1567. * Get repost element for content based modules.
  1568. *
  1569. * @param $iOwnerId integer value with owner profile ID.
  1570. * @param $sType string value with type (module name).
  1571. * @param $sAction string value with action (module action).
  1572. * @param $iObjectId integer value with object ID to be reposted.
  1573. * @param $aParams (optional) an array with additional params.
  1574. * @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.
  1575. *
  1576. * @see BxTimelineModule::serviceGetRepostElementBlock
  1577. */
  1578. /**
  1579. * @ref bx_timeline-get_repost_element_block "get_repost_element_block"
  1580. */
  1581. public function serviceGetRepostElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
  1582. {
  1583. if(!$this->isEnabled())
  1584. return '';
  1585. $aParams = array_merge($this->_oConfig->getRepostDefaults(), $aParams);
  1586. return $this->_oTemplate->getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
  1587. }
  1588. /**
  1589. * @page service Service Calls
  1590. * @section bx_timeline Timeline
  1591. * @subsection bx_timeline-repost Repost
  1592. * @subsubsection bx_timeline-get_repost_counter get_repost_counter
  1593. *
  1594. * @code bx_srv('bx_timeline', 'get_repost_counter', [...]); @endcode
  1595. *
  1596. * Get repost counter.
  1597. *
  1598. * @param $sType string value with type (module name).
  1599. * @param $sAction string value with action (module action).
  1600. * @param $iObjectId integer value with object ID to be reposted.
  1601. * @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.
  1602. *
  1603. * @see BxTimelineModule::serviceGetRepostCounter
  1604. */
  1605. /**
  1606. * @ref bx_timeline-get_repost_counter "get_repost_counter"
  1607. */
  1608. public function serviceGetRepostCounter($sType, $sAction, $iObjectId)
  1609. {
  1610. if(!$this->isEnabled())
  1611. return '';
  1612. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1613. return $this->_oTemplate->getRepostCounter($aReposted);
  1614. }
  1615. /**
  1616. * @page service Service Calls
  1617. * @section bx_timeline Timeline
  1618. * @subsection bx_timeline-repost Repost
  1619. * @subsubsection bx_timeline-get_repost_js_script get_repost_js_script
  1620. *
  1621. * @code bx_srv('bx_timeline', 'get_repost_js_script', [...]); @endcode
  1622. *
  1623. * Get repost JavaScript code.
  1624. *
  1625. * @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.
  1626. *
  1627. * @see BxTimelineModule::serviceGetRepostJsScript
  1628. */
  1629. /**
  1630. * @ref bx_timeline-get_repost_js_script "get_repost_js_script"
  1631. */
  1632. public function serviceGetRepostJsScript()
  1633. {
  1634. if(!$this->isEnabled())
  1635. return '';
  1636. return $this->_oTemplate->getRepostJsScript();
  1637. }
  1638. /**
  1639. * @page service Service Calls
  1640. * @section bx_timeline Timeline
  1641. * @subsection bx_timeline-repost Repost
  1642. * @subsubsection bx_timeline-get_repost_js_click get_repost_js_click
  1643. *
  1644. * @code bx_srv('bx_timeline', 'get_repost_js_click', [...]); @endcode
  1645. *
  1646. * Get repost JavaScript code for OnClick event.
  1647. *
  1648. * @param $iOwnerId integer value with owner profile ID.
  1649. * @param $sType string value with type (module name).
  1650. * @param $sAction string value with action (module action).
  1651. * @param $iObjectId integer value with object ID to be reposted.
  1652. * @return HTML string with JavaScript code to display in OnClick events of HTML elements.
  1653. *
  1654. * @see BxTimelineModule::serviceGetRepostJsClick
  1655. */
  1656. /**
  1657. * @ref bx_timeline-get_repost_js_click "get_repost_js_click"
  1658. */
  1659. public function serviceGetRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  1660. {
  1661. if(!$this->isEnabled())
  1662. return '';
  1663. return $this->_oTemplate->getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  1664. }
  1665. /**
  1666. * @page service Service Calls
  1667. * @section bx_timeline Timeline
  1668. * @subsection bx_timeline-repost Repost
  1669. * @subsubsection bx_timeline-repost repost
  1670. *
  1671. * @code bx_srv('bx_timeline', 'repost', [...]); @endcode
  1672. *
  1673. * Perform repost action.
  1674. *
  1675. * @param $iAuthorId integer value with performer profile ID.
  1676. * @param $iOwnerId integer value with repost event owner profile ID.
  1677. * @param $sType string value with type (module name).
  1678. * @param $sAction string value with action (module action).
  1679. * @param $iObjectId integer value with object ID to be reposted.
  1680. * @parem $bForce boolean value force reposting without ACL check.
  1681. * @return an array with error (code and message) or integer with newly created repost event ID.
  1682. *
  1683. * @see BxTimelineModule::serviceRepost
  1684. */
  1685. /**
  1686. * @ref bx_timeline-repost "repost"
  1687. */
  1688. public function serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $bForce = false)
  1689. {
  1690. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1691. if(empty($aReposted) || !is_array($aReposted))
  1692. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1693. $mixedAllowed = $this->isAllowedRepost($aReposted, true);
  1694. if(!$bForce && $mixedAllowed !== true)
  1695. return array('code' => 2, 'message' => strip_tags($mixedAllowed));
  1696. $bReposted = $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $iAuthorId);
  1697. if($bReposted)
  1698. return array('code' => 3, 'message' => _t('_bx_timeline_txt_err_already_reposted'));
  1699. $iId = $this->_oDb->insertEvent(array(
  1700. 'owner_id' => $iOwnerId,
  1701. 'type' => $this->_oConfig->getPrefix('common_post') . 'repost',
  1702. 'action' => '',
  1703. 'object_id' => $iAuthorId,
  1704. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault('object'),
  1705. 'content' => serialize(array(
  1706. 'type' => $sType,
  1707. 'action' => $sAction,
  1708. 'object_id' => $iObjectId,
  1709. )),
  1710. 'title' => '',
  1711. 'description' => ''
  1712. ));
  1713. if(empty($iId))
  1714. return array('code' => 4, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1715. $this->onRepost($iId, $aReposted);
  1716. return $iId;
  1717. }
  1718. /**
  1719. * @page service Service Calls
  1720. * @section bx_timeline Timeline
  1721. * @subsection bx_timeline-repost Repost
  1722. * @subsubsection bx_timeline-repost_by_id repost_by_id
  1723. *
  1724. * @code bx_srv('bx_timeline', 'repost_by_id', [...]); @endcode
  1725. *
  1726. * Perform repost action by Timeline event ID.
  1727. *
  1728. * @param $iAuthorId integer value with performer profile ID.
  1729. * @param $iOwnerId integer value with repost event owner profile ID.
  1730. * @param $iEventId integer value with event ID which will be reposted.
  1731. * @parem $bForce boolean value force reposting without ACL check.
  1732. * @return an array with error (code and message) or integer with newly created repost event ID.
  1733. *
  1734. * @see BxTimelineModule::serviceRepostById
  1735. */
  1736. /**
  1737. * @ref bx_timeline-repost_by_id "repost_by_id"
  1738. */
  1739. public function serviceRepostById($iAuthorId, $iOwnerId, $iEventId, $bForce = false)
  1740. {
  1741. $aEvent = $this->_oDb->getEntriesBy(array('type' => 'id', 'id' => $iEventId));
  1742. if(empty($aEvent) || !is_array($aEvent))
  1743. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1744. $sType = $aEvent['type'];
  1745. $sAction = $aEvent['action'];
  1746. $iObjectId = $this->_oConfig->isSystem($sType, $sAction) ? $aEvent['object_id'] : $aEvent['id'];
  1747. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  1748. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  1749. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1750. if(empty($aReposted) || !is_array($aReposted))
  1751. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1752. $aRepostedData = unserialize($aEvent['content']);
  1753. $sType = $aRepostedData['type'];
  1754. $sAction = $aRepostedData['action'];
  1755. $iObjectId = $aRepostedData['object_id'];
  1756. }
  1757. return $this->serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $bForce);
  1758. }
  1759. /**
  1760. * @page service Service Calls
  1761. * @section bx_timeline Timeline
  1762. * @subsection bx_timeline-other Other
  1763. * @subsubsection bx_timeline-update update
  1764. *
  1765. * @code bx_srv('bx_timeline', 'update', [...]); @endcode
  1766. *
  1767. * Update timeline event by ID.
  1768. *
  1769. * @param $iEventId integer value with event ID.
  1770. * @param $aSet an array with key=>value pairs for fields which should be updated.
  1771. * @return boolean value with the result of operation.
  1772. *
  1773. * @see BxTimelineModule::serviceUpdate
  1774. */
  1775. /**
  1776. * @ref bx_timeline-update "update"
  1777. */
  1778. public function serviceUpdate($iEventId, $aSet)
  1779. {
  1780. if(empty($iEventId))
  1781. return false;
  1782. return (int)$this->_oDb->updateEvent($aSet, array('id' => $iEventId)) > 0;
  1783. }
  1784. /**
  1785. * @page service Service Calls
  1786. * @section bx_timeline Timeline
  1787. * @subsection bx_timeline-other Other
  1788. * @subsubsection bx_timeline-get_menu_item_addon_comment get_menu_item_addon_comment
  1789. *
  1790. * @code bx_srv('bx_timeline', 'get_menu_item_addon_comment', [...]); @endcode
  1791. *
  1792. * Get addon for Comment menu item.
  1793. *
  1794. * @param $sSystem string value with comments engine system.
  1795. * @param $iObjectId integer value with object ID.
  1796. * @return HTML string to display in menu item.
  1797. *
  1798. * @see BxTimelineModule::serviceGetMenuItemAddonComment
  1799. */
  1800. /**
  1801. * @ref bx_timeline-get_menu_item_addon_comment "get_menu_item_addon_comment"
  1802. */
  1803. public function serviceGetMenuItemAddonComment($sSystem, $iObjectId, $aBrowseParams = array())
  1804. {
  1805. if(empty($sSystem) || empty($iObjectId))
  1806. return '';
  1807. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  1808. if($oCmts === false)
  1809. return '';
  1810. $iCounter = (int)$oCmts->getCommentsCount();
  1811. if(empty($iCounter))
  1812. return '';
  1813. return $this->_oTemplate->parseLink('javascript:void(0)', $iCounter, array(
  1814. 'class' => 'bx-menu-item-addon',
  1815. 'title' => _t('_bx_timeline_menu_item_title_item_comment'),
  1816. 'onclick' => "javascript:" . $this->_oConfig->getJsObjectView($aBrowseParams) . ".commentItem(this, '" . $sSystem . "', " . $iObjectId . ")"
  1817. ));
  1818. }
  1819. /**
  1820. * @page service Service Calls
  1821. * @section bx_timeline Timeline
  1822. * @subsection bx_timeline-other Other
  1823. * @subsubsection bx_timeline-get_settings_checker_helper get_settings_checker_helper
  1824. *
  1825. * @code bx_srv('bx_timeline', 'get_settings_checker_helper', [...]); @endcode
  1826. *
  1827. * Get Checker Helper class name for Forms engine.
  1828. *
  1829. * @return string with Checker Helper class name.
  1830. *
  1831. * @see BxTimelineModule::serviceGetSettingsCheckerHelper
  1832. */
  1833. /**
  1834. * @ref bx_timeline-get_settings_checker_helper "get_settings_checker_helper"
  1835. */
  1836. public function serviceGetSettingsCheckerHelper()
  1837. {
  1838. bx_import('FormCheckerHelper', $this->_aModule);
  1839. return 'BxTimelineFormCheckerHelper';
  1840. }
  1841. /**
  1842. * @page service Service Calls
  1843. * @section bx_timeline Timeline
  1844. * @subsection bx_timeline-other Other
  1845. * @subsubsection bx_timeline-get_options_videos_autoplay get_options_videos_autoplay
  1846. *
  1847. * @code bx_srv('bx_timeline', 'get_options_videos_autoplay', [...]); @endcode
  1848. *
  1849. * Get an array with available options for 'Videos autoplay in Timeline' setting.
  1850. *
  1851. * @return an array with available options represented as key => value pairs.
  1852. *
  1853. * @see BxTimelineModule::serviceGetOptionsVideosAutoplay
  1854. */
  1855. /**
  1856. * @ref bx_timeline-get_options_videos_autoplay "get_options_videos_autoplay"
  1857. */
  1858. public function serviceGetOptionsVideosAutoplay()
  1859. {
  1860. $aOptions = array(BX_TIMELINE_VAP_OFF, BX_TIMELINE_VAP_ON_MUTE, BX_TIMELINE_VAP_ON);
  1861. $aResult = array();
  1862. foreach($aOptions as $sOption)
  1863. $aResult[] = array(
  1864. 'key' => $sOption,
  1865. 'value' => _t('_bx_timeline_option_videos_autoplay_' . $sOption)
  1866. );
  1867. return $aResult;
  1868. }
  1869. /**
  1870. * @page service Service Calls
  1871. * @section bx_timeline Timeline
  1872. * @subsection bx_timeline-other Other
  1873. * @subsubsection bx_timeline-get_live_update get_live_update
  1874. *
  1875. * @code bx_srv('bx_timeline', 'get_live_update', [...]); @endcode
  1876. *
  1877. * Get an array with actual Live Update info. Only one live update notification for all new events.
  1878. *
  1879. * @return an array with Live Update info.
  1880. *
  1881. * @see BxTimelineModule::serviceGetLiveUpdate
  1882. */
  1883. /**
  1884. * @ref bx_timeline-get_live_update "get_live_update"
  1885. */
  1886. public function serviceGetLiveUpdate($aBrowseParams, $iProfileId, $iCount = 0, $iInit = 0)
  1887. {
  1888. $sKey = $this->_oConfig->getLiveUpdateKey($aBrowseParams);
  1889. bx_import('BxDolSession');
  1890. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  1891. return false;
  1892. $aParams = $this->_prepareParams($aBrowseParams);
  1893. $aParams['filter'] = BX_TIMELINE_FILTER_OTHER_VIEWER;
  1894. $aParams['count'] = true;
  1895. $iCountNew = $this->_oDb->getEvents($aParams);
  1896. if($iCountNew == $iCount)
  1897. return false;
  1898. if((int)$iInit != 0)
  1899. return array('count' => $iCountNew);
  1900. return array(
  1901. 'count' => $iCountNew, // required (for initialization and visualization)
  1902. 'method' => $this->_oConfig->getJsObjectView($aBrowseParams) . '.showLiveUpdate(oData)', // required (for visualization)
  1903. 'data' => array(
  1904. 'code' => $this->_oTemplate->getLiveUpdate($aBrowseParams, $iProfileId, $iCount, $iCountNew)
  1905. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  1906. );
  1907. }
  1908. /**
  1909. * @page service Service Calls
  1910. * @section bx_timeline Timeline
  1911. * @subsection bx_timeline-other Other
  1912. * @subsubsection bx_timeline-get_live_updates get_live_updates
  1913. *
  1914. * @code bx_srv('bx_timeline', 'get_live_updates', [...]); @endcode
  1915. *
  1916. * Get an array with actual Live Update info. Separate live update notification for each new Event.
  1917. *
  1918. * Note. This way to display live update notifications isn't used for now.
  1919. * See BxTimelineModule::serviceGetLiveUpdate method instead.
  1920. *
  1921. * @return an array with Live Update info.
  1922. *
  1923. * @see BxTimelineModule::serviceGetLiveUpdates
  1924. */
  1925. /**
  1926. * @ref bx_timeline-get_live_updates "get_live_updates"
  1927. */
  1928. public function serviceGetLiveUpdates($aBrowseParams, $iProfileId, $iCount = 0, $iInit = 0)
  1929. {
  1930. $sKey = $this->_oConfig->getLiveUpdateKey($aBrowseParams);
  1931. bx_import('BxDolSession');
  1932. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  1933. return false;
  1934. $aParams = $this->_prepareParams($aBrowseParams);
  1935. $aParams['filter'] = BX_TIMELINE_FILTER_OTHER_VIEWER;
  1936. $aParams['count'] = true;
  1937. $iCountNew = $this->_oDb->getEvents($aParams);
  1938. if($iCountNew == $iCount)
  1939. return false;
  1940. if((int)$iInit != 0)
  1941. return array('count' => $iCountNew);
  1942. return array(
  1943. 'count' => $iCountNew, // required (for initialization and visualization)
  1944. 'method' => $this->_oConfig->getJsObjectView($aBrowseParams) . '.showLiveUpdates(oData)', // required (for visualization)
  1945. 'data' => array(
  1946. 'code' => $this->_oTemplate->getLiveUpdates($aBrowseParams, $iProfileId, $iCount, $iCountNew)
  1947. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  1948. );
  1949. }
  1950. /**
  1951. * @page service Service Calls
  1952. * @section bx_timeline Accounts
  1953. * @subsection bx_timeline-other Other
  1954. * @subsubsection bx_timeline-get_menu_addon_manage_tools get_menu_addon_manage_tools
  1955. *
  1956. * @code bx_srv('bx_timeline', 'get_menu_addon_manage_tools', [...]); @endcode
  1957. *
  1958. * Get number of 'hidden' events for User End -> Dasboard page -> Manage block.
  1959. *
  1960. * @return integer number of 'hidden' events
  1961. *
  1962. * @see BxTimelineModule::serviceGetMenuAddonManageTools
  1963. */
  1964. /**
  1965. * @ref bx_timeline-get_menu_addon_manage_tools "get_menu_addon_manage_tools"
  1966. */
  1967. public function serviceGetMenuAddonManageTools()
  1968. {
  1969. bx_import('SearchResult', $this->_aModule);
  1970. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  1971. $oSearch = new $sClass();
  1972. $oSearch->fillFilters(array(
  1973. 'status' => BX_TIMELINE_STATUS_HIDDEN
  1974. ));
  1975. $oSearch->unsetPaginate();
  1976. return $oSearch->getNum();
  1977. }
  1978. /*
  1979. * COMMON METHODS
  1980. */
  1981. public function deleteEvent($aEvent)
  1982. {
  1983. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->deleteEvent(array('id' => (int)$aEvent['id'])))
  1984. return false;
  1985. $this->onDelete($aEvent);
  1986. return true;
  1987. }
  1988. public function addAttachLink($aValues, $sDisplay = false)
  1989. {
  1990. $CNF = &$this->_oConfig->CNF;
  1991. if(!$sDisplay)
  1992. $sDisplay = $this->_oConfig->getObject('form_display_attach_link_add');
  1993. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $sDisplay, $this->_oTemplate);
  1994. if(!$oForm)
  1995. return array('message' => '_sys_txt_error_occured');
  1996. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  1997. $oForm->aParams['csrf']['disable'] = true;
  1998. if(!empty($oForm->aParams['db']['submit_name'])) {
  1999. $sSubmitName = $oForm->aParams['db']['submit_name'];
  2000. if(!isset($oForm->aInputs[$sSubmitName])) {
  2001. if(isset($oForm->aInputs[$CNF['FIELD_CONTROLS']]))
  2002. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  2003. if(!is_numeric($mixedIndex) || empty($aInput['name']) || $aInput['name'] != $sSubmitName)
  2004. continue;
  2005. $aValues[$sSubmitName] = $aInput['value'];
  2006. }
  2007. }
  2008. else
  2009. $aValues[$sSubmitName] = $oForm->aInputs[$sSubmitName]['value'];
  2010. }
  2011. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  2012. $oForm->initChecker(array(), $aValues);
  2013. if(!$oForm->isSubmittedAndValid())
  2014. return array('message' => '_sys_txt_error_occured');
  2015. return $this->_addLink($oForm);
  2016. }
  2017. public function getFormAttachLink()
  2018. {
  2019. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $this->_oConfig->getObject('form_display_attach_link_add'), $this->_oTemplate);
  2020. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_attach_link_form/';
  2021. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  2022. $oForm->initChecker();
  2023. if($oForm->isSubmittedAndValid())
  2024. return $this->_addLink($oForm);
  2025. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  2026. }
  2027. public function getFormPost($aParams = array())
  2028. {
  2029. $iUserId = $this->getUserId();
  2030. $oForm = $this->getFormPostObject($aParams);
  2031. $oForm->initChecker();
  2032. $bAjaxMode = $oForm->isAjaxMode();
  2033. $bDynamicMode = $bAjaxMode;
  2034. if($oForm->isSubmittedAndValid()) {
  2035. list($sUserName) = $this->getUserInfo($iUserId);
  2036. $sType = $oForm->getCleanValue('type');
  2037. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  2038. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  2039. $aContent = array();
  2040. //--- Process Text ---//
  2041. $sText = $oForm->getCleanValue('text');
  2042. $sText = $this->_prepareTextForSave($sText);
  2043. $bText = !empty($sText);
  2044. if($bText)
  2045. $aContent['text'] = $sText;
  2046. //--- Process Context and Privacy ---//
  2047. $iOwnerId = (int)$oForm->getCleanValue('owner_id');
  2048. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  2049. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  2050. if(empty($iObjectPrivacyView))
  2051. $iObjectPrivacyView = $iObjectPrivacyViewDefault;
  2052. else if($iObjectPrivacyView < 0)
  2053. $iOwnerId = abs($iObjectPrivacyView);
  2054. //--- Process Link ---//
  2055. $aLinkIds = $oForm->getCleanValue('link');
  2056. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  2057. //--- Process Media ---//
  2058. $aPhotoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_PHOTO);
  2059. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  2060. $aVideoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_VIDEO);
  2061. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  2062. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds) {
  2063. $oForm->aInputs['text']['error'] = _t('_bx_timeline_txt_err_empty_post');
  2064. $oForm->setValid(false);
  2065. return $this->_prepareResponse(array('form' => $oForm->getCode($bDynamicMode), 'form_id' => $oForm->id), $bAjaxMode);
  2066. }
  2067. $sTitle = $bText ? $this->_oConfig->getTitle($sText) : $this->_oConfig->getTitleDefault($bLinkIds, $bPhotoIds, $bVideoIds);
  2068. $sDescription = _t('_bx_timeline_txt_user_added_sample', '{profile_name}', _t('_bx_timeline_txt_sample_with_article'));
  2069. /**
  2070. * Unset 'text' input because its data was already processed
  2071. * and will be saved via additional values which were passed
  2072. * to BxDolForm::insert method.
  2073. */
  2074. unset($oForm->aInputs['text']);
  2075. $iId = $oForm->insert(array(
  2076. 'owner_id' => $iOwnerId,
  2077. 'object_id' => $iUserId,
  2078. 'object_privacy_view' => $iObjectPrivacyView,
  2079. 'content' => serialize($aContent),
  2080. 'title' => $sTitle,
  2081. 'description' => $sDescription
  2082. ));
  2083. if(!empty($iId)) {
  2084. $aContent = array_merge($aContent, array(
  2085. 'timeline_group' => array(
  2086. 'by' => $this->getName() . '_' . $iUserId . '_' . $iId,
  2087. 'field' => 'owner_id'
  2088. )
  2089. ));
  2090. $this->_oDb->updateEvent(array('content' => serialize($aContent)), array('id' => $iId));
  2091. //--- Process Meta ---//
  2092. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  2093. if($bText)
  2094. $oMetatags->metaAdd($iId, $sText);
  2095. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  2096. //--- Process Link ---//
  2097. if($bLinkIds)
  2098. foreach($aLinkIds as $iLinkId)
  2099. $this->_oDb->saveLink($iId, $iLinkId);
  2100. //--- Process Media ---//
  2101. if($bPhotoIds)
  2102. $this->_saveMedia(BX_TIMELINE_MEDIA_PHOTO, $iId, $aPhotoIds);
  2103. if($bVideoIds)
  2104. $this->_saveMedia(BX_TIMELINE_MEDIA_VIDEO, $iId, $aVideoIds);
  2105. $this->onPost($iId);
  2106. return $this->_prepareResponse(array('id' => $iId), $bAjaxMode, array(
  2107. 'redirect' => $this->_oConfig->getItemViewUrl(array('id' => $iId))
  2108. ));
  2109. }
  2110. return $this->_prepareResponse(array('message' => _t('_bx_timeline_txt_err_cannot_perform_action')), $bAjaxMode);
  2111. }
  2112. return $this->_prepareResponse(array('form' => $oForm->getCode($bDynamicMode), 'form_id' => $oForm->id), $bAjaxMode && $oForm->isSubmitted());
  2113. }
  2114. public function getFormEdit($iId, $aParams = array(), $aBrowseParams = array())
  2115. {
  2116. $CNF = &$this->_oConfig->CNF;
  2117. $sJsObjectView = $this->_oConfig->getJsObjectView($aBrowseParams);
  2118. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  2119. if(empty($aEvent) || !is_array($aEvent))
  2120. return array();
  2121. $aContent = unserialize($aEvent['content']);
  2122. if(is_array($aContent) && !empty($aContent['text']))
  2123. $aEvent['text'] = $aContent['text'];
  2124. $bDynamicMode = isset($aParams['dynamic_mode']) ? (bool)$aParams['dynamic_mode'] : false;
  2125. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  2126. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_edit';
  2127. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  2128. $oForm->setId($this->_oConfig->getHtmlIds('view', 'edit_form') . $iId);
  2129. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'edit/' . $iId ;
  2130. if(!empty($aBrowseParams) && is_array($aBrowseParams))
  2131. $oForm->aFormAttrs['action'] = $this->_oConfig->addBrowseParams($oForm->aFormAttrs['action'], $aBrowseParams);
  2132. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  2133. if(!is_numeric($mixedIndex))
  2134. continue;
  2135. $oForm->aInputs[$CNF['FIELD_CONTROLS']][$mixedIndex]['attrs'] = bx_replace_markers($aInput['attrs'], array(
  2136. 'js_object_view' => $sJsObjectView,
  2137. 'content_id' => $iId
  2138. ));
  2139. }
  2140. $oForm->initChecker($aEvent);
  2141. if($oForm->isSubmittedAndValid()) {
  2142. $aContent = array();
  2143. //--- Process Text ---//
  2144. $sText = $oForm->getCleanValue('text');
  2145. $sText = $this->_prepareTextForSave($sText);
  2146. $bText = !empty($sText);
  2147. unset($oForm->aInputs['text']);
  2148. if($bText)
  2149. $aContent['text'] = $sText;
  2150. $aValsToAdd = array(
  2151. 'content' => serialize($aContent)
  2152. );
  2153. //--- Process Privacy ---//
  2154. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  2155. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  2156. if(empty($iObjectPrivacyView))
  2157. $aValsToAdd = array_merge($aValsToAdd, array(
  2158. 'object_privacy_view' => $iObjectPrivacyViewDefault
  2159. ));
  2160. else if($iObjectPrivacyView < 0)
  2161. $aValsToAdd = array_merge($aValsToAdd, array(
  2162. 'owner_id' => abs($iObjectPrivacyView),
  2163. 'object_privacy_view' => $iObjectPrivacyViewDefault
  2164. ));
  2165. if(!$oForm->update($iId, $aValsToAdd))
  2166. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  2167. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  2168. if($bText)
  2169. $oMetatags->metaAdd($iId, $sText);
  2170. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  2171. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iId);
  2172. $this->_oDb->deleteCache(array('event_id' => $iId));
  2173. return array(
  2174. 'id' => $iId
  2175. );
  2176. }
  2177. return array(
  2178. 'id' => $iId,
  2179. 'form' => $oForm->getCode($bDynamicMode),
  2180. 'form_id' => $oForm->id,
  2181. 'eval' => $sJsObjectView . '.onEditPost(oData)'
  2182. );
  2183. }
  2184. public function getFormPostObject($aParams)
  2185. {
  2186. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  2187. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_add';
  2188. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  2189. /**
  2190. * Note. 'ajax_mode' parameter isn't checked because
  2191. * timeline post form works as Ajax form by default.
  2192. */
  2193. $sParamsKey = 'visibility_autoselect';
  2194. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  2195. $oForm->setVisibilityAutoselect((bool)$aParams[$sParamsKey]);
  2196. $oForm->init();
  2197. return $oForm;
  2198. }
  2199. public function getCmtsObject($sSystem, $iId)
  2200. {
  2201. if(empty($sSystem) || (int)$iId == 0)
  2202. return false;
  2203. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2204. if(!$oCmts || !$oCmts->isEnabled())
  2205. return false;
  2206. return $oCmts;
  2207. }
  2208. public function getViewObject($sSystem, $iId)
  2209. {
  2210. if(empty($sSystem) || (int)$iId == 0)
  2211. return false;
  2212. $oView = BxDolView::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2213. if(!$oView || !$oView->isEnabled())
  2214. return false;
  2215. return $oView;
  2216. }
  2217. public function getVoteObject($sSystem, $iId)
  2218. {
  2219. if(empty($sSystem) || (int)$iId == 0)
  2220. return false;
  2221. $oVote = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2222. if(!$oVote || !$oVote->isEnabled())
  2223. return false;
  2224. return $oVote;
  2225. }
  2226. public function getReactionObject($sSystem, $iId)
  2227. {
  2228. if(empty($sSystem) || (int)$iId == 0)
  2229. return false;
  2230. $oReaction = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2231. if(!$oReaction || !$oReaction->isEnabled())
  2232. return false;
  2233. return $oReaction;
  2234. }
  2235. public function getScoreObject($sSystem, $iId)
  2236. {
  2237. if(empty($sSystem) || (int)$iId == 0)
  2238. return false;
  2239. $oScore = BxDolScore::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2240. if(!$oScore || !$oScore->isEnabled())
  2241. return false;
  2242. return $oScore;
  2243. }
  2244. public function getReportObject($sSystem, $iId)
  2245. {
  2246. if(empty($sSystem) || (int)$iId == 0)
  2247. return false;
  2248. $oReport = BxDolReport::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2249. if(!$oReport || !$oReport->isEnabled())
  2250. return false;
  2251. return $oReport;
  2252. }
  2253. public function getAttachmentsMenuObject()
  2254. {
  2255. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post_attachments'), $this->_oTemplate);
  2256. $oMenu->addMarkers(array(
  2257. 'js_object' => $this->_oConfig->getJsObject('post'),
  2258. ));
  2259. return $oMenu;
  2260. }
  2261. public function getManageMenuObject()
  2262. {
  2263. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'), $this->_oTemplate);
  2264. }
  2265. public function getCacheItemObject()
  2266. {
  2267. $oCacheEngine = bx_instance('BxDolCache' . $this->_oConfig->getCacheItemEngine());
  2268. if(!$oCacheEngine->isAvailable())
  2269. $oCacheEngine = bx_instance('BxDolCacheFile');
  2270. return $oCacheEngine;
  2271. }
  2272. //--- Check permissions methods ---//
  2273. public function isModerator()
  2274. {
  2275. $sModule = $this->getName();
  2276. $iUserId = (int)$this->getUserId();
  2277. $aCheckResult = checkActionModule($iUserId, 'edit', $sModule);
  2278. if($aCheckResult[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2279. return true;
  2280. $aCheckResult = checkActionModule($iUserId, 'delete', $sModule);
  2281. if($aCheckResult[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2282. return true;
  2283. return false;
  2284. }
  2285. public function isAllowedPost($bPerform = false)
  2286. {
  2287. if(isAdmin())
  2288. return true;
  2289. $iUserId = $this->getUserId();
  2290. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  2291. if($aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  2292. return $aCheckResult[CHECK_ACTION_MESSAGE];
  2293. if(!empty($this->_iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId)) !== false) {
  2294. if($oProfileOwner->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  2295. return _t('_sys_txt_access_denied');
  2296. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_post', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2297. }
  2298. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2299. }
  2300. public function isAllowedView($aEvent, $bPerform = false)
  2301. {
  2302. $CNF = $this->_oConfig->CNF;
  2303. if((int)$aEvent[$CNF['FIELD_OWNER_ID']] == 0)
  2304. return true;
  2305. $oProfileOwner = BxDolProfile::getInstance($aEvent[$CNF['FIELD_OWNER_ID']]);
  2306. if($oProfileOwner && $oProfileOwner->checkAllowedProfileView() !== CHECK_ACTION_RESULT_ALLOWED)
  2307. return false;
  2308. return true;
  2309. }
  2310. public function isAllowedEdit($aEvent, $bPerform = false)
  2311. {
  2312. if(!isLogged())
  2313. return false;
  2314. //--- System posts and Reposts cannot be edited at all.
  2315. if(!$this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) || $aEvent['type'] == $this->_oConfig->getPrefix('common_post') . 'repost')
  2316. return false;
  2317. if(isAdmin())
  2318. return true;
  2319. $iUserId = (int)$this->getUserId();
  2320. $iOwnerId = (int)$aEvent['owner_id'];
  2321. $iObjectId = abs((int)$aEvent['object_id']);
  2322. if($iObjectId == $iUserId && $this->_oConfig->isAllowEdit())
  2323. return true;
  2324. $aCheckResult = checkActionModule($iUserId, 'edit', $this->getName(), $bPerform);
  2325. if(!empty($iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($iOwnerId)) !== false)
  2326. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_edit', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2327. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2328. }
  2329. public function isAllowedDelete($aEvent, $bPerform = false)
  2330. {
  2331. if(!isLogged())
  2332. return false;
  2333. if(isAdmin())
  2334. return true;
  2335. $iUserId = (int)$this->getUserId();
  2336. $iOwnerId = (int)$aEvent['owner_id'];
  2337. $iObjectId = abs((int)$aEvent['object_id']);
  2338. if((($iOwnerId == $iUserId && $this->_oConfig->isAllowDelete()) || ($this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && $iObjectId == $iUserId)))
  2339. return true;
  2340. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  2341. if(!empty($iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($iOwnerId)) !== false)
  2342. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_delete', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2343. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2344. }
  2345. public function isAllowedComment($aEvent, $bPerform = false)
  2346. {
  2347. $mixedComments = $this->getCommentsData($aEvent['comments']);
  2348. if($mixedComments === false)
  2349. return false;
  2350. list($sSystem, $iObjectId) = $mixedComments;
  2351. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  2352. if($oCmts->isViewAllowed() !== CHECK_ACTION_RESULT_ALLOWED)
  2353. return false;
  2354. $oCmts->addCssJs();
  2355. $bResult = true;
  2356. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false) {
  2357. if($oProfileOwner->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  2358. return false;
  2359. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_comment', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2360. }
  2361. return $bResult;
  2362. }
  2363. public function isAllowedViewCounter($aEvent, $bPerform = false)
  2364. {
  2365. $mixedViews = $this->getViewsData($aEvent['views']);
  2366. if($mixedViews === false)
  2367. return false;
  2368. list($sSystem, $iObjectId) = $mixedViews;
  2369. $oView = $this->getViewObject($sSystem, $iObjectId);
  2370. if(!$oView->isAllowedViewView($bPerform))
  2371. return false;
  2372. $bResult = true;
  2373. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2374. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view_counter', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2375. return $bResult;
  2376. }
  2377. public function isAllowedVote($aEvent, $bPerform = false)
  2378. {
  2379. $mixedVotes = $this->getVotesData($aEvent['votes']);
  2380. if($mixedVotes === false)
  2381. return false;
  2382. list($sSystem, $iObjectId) = $mixedVotes;
  2383. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  2384. if(!$oVote->isAllowedVote($bPerform))
  2385. return false;
  2386. $bResult = true;
  2387. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2388. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2389. return $bResult;
  2390. }
  2391. public function isAllowedReaction($aEvent, $bPerform = false)
  2392. {
  2393. $mixedReactions = $this->getReactionsData($aEvent['reactions']);
  2394. if($mixedReactions === false)
  2395. return false;
  2396. list($sSystem, $iObjectId) = $mixedReactions;
  2397. $oReaction = $this->getReactionObject($sSystem, $iObjectId);
  2398. if(!$oReaction->isAllowedVote($bPerform))
  2399. return false;
  2400. $bResult = true;
  2401. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2402. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_reaction', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2403. return $bResult;
  2404. }
  2405. public function isAllowedScore($aEvent, $bPerform = false)
  2406. {
  2407. $mixedScores = $this->getScoresData($aEvent['scores']);
  2408. if($mixedScores === false)
  2409. return false;
  2410. list($sSystem, $iObjectId) = $mixedScores;
  2411. $oScore = $this->getScoreObject($sSystem, $iObjectId);
  2412. if(!$oScore->isAllowedVote($bPerform))
  2413. return false;
  2414. $bResult = true;
  2415. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2416. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_score', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2417. return $bResult;
  2418. }
  2419. public function isAllowedReport($aEvent, $bPerform = false)
  2420. {
  2421. $mixedReports = $this->getReportsData($aEvent['reports']);
  2422. if($mixedReports === false)
  2423. return false;
  2424. list($sSystem, $iObjectId) = $mixedReports;
  2425. $oReport = $this->getReportObject($sSystem, $iObjectId);
  2426. if(!$oReport->isAllowedReport($bPerform))
  2427. return false;
  2428. $bResult = true;
  2429. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2430. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_report', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2431. return $bResult;
  2432. }
  2433. public function isAllowedRepost($aEvent, $bPerform = false)
  2434. {
  2435. $iUserId = (int)$this->getUserId();
  2436. if($iUserId == 0)
  2437. return false;
  2438. $iPrivacy = (int)$aEvent['object_privacy_view'];
  2439. if($iPrivacy >= 0 && !in_array($iPrivacy, array(BX_DOL_PG_ALL, BX_DOL_PG_MEMBERS)))
  2440. return false;
  2441. if(isAdmin())
  2442. return true;
  2443. $aCheckResult = checkActionModule($iUserId, 'repost', $this->getName(), $bPerform);
  2444. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2445. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_repost', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2446. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2447. }
  2448. public function isAllowedSend($aEvent, $bPerform = false)
  2449. {
  2450. if(!$this->_oDb->isEnabledByName('bx_convos'))
  2451. return false;
  2452. if(isAdmin())
  2453. return true;
  2454. $iUserId = (int)$this->getUserId();
  2455. if($iUserId == 0)
  2456. return false;
  2457. $aCheckResult = checkActionModule($iUserId, 'send', $this->getName(), $bPerform);
  2458. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2459. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_send', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2460. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2461. }
  2462. /**
  2463. * Pin - "Pin here" - pin the post on Profile Timeline for profile owner.
  2464. * Can be done by profile owner for himself or by admin for profile owner to see.
  2465. * @param type $aEvent
  2466. * @param type $bPerform
  2467. * @return boolean
  2468. */
  2469. public function isAllowedPin($aEvent, $bPerform = false)
  2470. {
  2471. if((int)$aEvent['pinned'] != 0)
  2472. return false;
  2473. return $this->_isAllowedPin($aEvent, $bPerform);
  2474. }
  2475. public function isAllowedUnpin($aEvent, $bPerform = false)
  2476. {
  2477. if((int)$aEvent['pinned'] == 0)
  2478. return false;
  2479. return $this->_isAllowedPin($aEvent, $bPerform);
  2480. }
  2481. /**
  2482. * Stick - "Pin for All" - pin the post on Public Timeline for everybody to see.
  2483. * Is available for Administrators/Moderators only.
  2484. * @param type $aEvent
  2485. * @param type $bPerform
  2486. * @return boolean
  2487. */
  2488. public function isAllowedStick($aEvent, $bPerform = false)
  2489. {
  2490. if((int)$aEvent['sticked'] != 0)
  2491. return false;
  2492. return $this->_isAllowedStick($aEvent, $bPerform);
  2493. }
  2494. public function isAllowedUnstick($aEvent, $bPerform = false)
  2495. {
  2496. if((int)$aEvent['sticked'] == 0)
  2497. return false;
  2498. return $this->_isAllowedStick($aEvent, $bPerform);
  2499. }
  2500. public function isAllowedPromote($aEvent, $bPerform = false)
  2501. {
  2502. if((int)$aEvent['promoted'] != 0)
  2503. return false;
  2504. return $this->_isAllowedPromote($aEvent, $bPerform);
  2505. }
  2506. public function isAllowedUnpromote($aEvent, $bPerform = false)
  2507. {
  2508. if((int)$aEvent['promoted'] == 0)
  2509. return false;
  2510. return $this->_isAllowedPromote($aEvent, $bPerform);
  2511. }
  2512. public function isAllowedMore($aEvent, $bPerform = false)
  2513. {
  2514. $oMoreMenu = $this->getManageMenuObject();
  2515. $oMoreMenu->setEvent($aEvent);
  2516. return $oMoreMenu->isVisible();
  2517. }
  2518. public function checkAllowedView ($aContentInfo, $isPerformAction = false)
  2519. {
  2520. if(!$this->isAllowedView($aContentInfo, $isPerformAction))
  2521. return _t('_sys_txt_access_denied');
  2522. return CHECK_ACTION_RESULT_ALLOWED;
  2523. }
  2524. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  2525. {
  2526. $CNF = $this->_oConfig->CNF;
  2527. $iOwner = (int)$aContentInfo[$CNF['FIELD_OWNER_ID']];
  2528. if($iOwner == 0) //--- in case of Public Timeline.
  2529. return CHECK_ACTION_RESULT_ALLOWED;
  2530. $oOwner = BxDolProfile::getInstance($iOwner);
  2531. if(!$oOwner) //--- in case of non-existed Timeline owner.
  2532. return _t('_sys_txt_access_denied');
  2533. $mixedResult = $oOwner->checkAllowedProfileView();
  2534. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  2535. return $mixedResult;
  2536. return CHECK_ACTION_RESULT_ALLOWED;
  2537. }
  2538. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  2539. {
  2540. $sError = '_sys_txt_access_denied';
  2541. $aContentInfo = $this->_oTemplate->getDataCached($aContentInfo);
  2542. if($aContentInfo === false)
  2543. return _t($sError);
  2544. if(!$this->isAllowedComment($aContentInfo, $isPerformAction))
  2545. return _t($sError);
  2546. return CHECK_ACTION_RESULT_ALLOWED;
  2547. }
  2548. public function onPost($iContentId)
  2549. {
  2550. $CNF = &$this->_oConfig->CNF;
  2551. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2552. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  2553. //--- Request event's data from content module and update it in the Timeline DB.
  2554. $this->_oTemplate->getDataCached($aEvent);
  2555. $sPostType = 'system';
  2556. $iSenderId = $iObjectAuthorId = (int)$aEvent['owner_id'];
  2557. }
  2558. else {
  2559. $sPostType = 'common';
  2560. $iSenderId = $iObjectAuthorId = (int)$aEvent['object_id'];
  2561. }
  2562. //--- Event -> Post/Defer for Alerts Engine ---//
  2563. $sAction = ($aEvent[$CNF['FIELD_STATUS']] == BX_TIMELINE_STATUS_AWAITING ? 'defer' : 'post') . '_' . $sPostType;
  2564. bx_alert($this->_oConfig->getObject('alert'), $sAction, $iContentId, $iSenderId, array(
  2565. 'owner_id' => $aEvent['owner_id'],
  2566. 'object_author_id' => $iObjectAuthorId,
  2567. 'privacy_view' => $aEvent['object_privacy_view'],
  2568. ));
  2569. //--- Event -> Post for Alerts Engine ---//
  2570. }
  2571. public function onPublished($iContentId)
  2572. {
  2573. $CNF = &$this->_oConfig->CNF;
  2574. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2575. //--- Clear Item cache
  2576. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iContentId);
  2577. //--- Clear Feed cache
  2578. $this->_oDb->deleteCache(array('context_id' => $aEvent[$CNF['FIELD_OWNER_ID']]));
  2579. $this->onPost($iContentId);
  2580. }
  2581. public function onFailed($iContentId)
  2582. {
  2583. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2584. //--- Clear Item cache
  2585. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iContentId);
  2586. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  2587. //--- Request event's data from content module and update it in the Timeline DB.
  2588. $this->_oTemplate->getDataCached($aEvent);
  2589. $sPostType = 'system';
  2590. $iSenderId = $iObjectAuthorId = (int)$aEvent['owner_id'];
  2591. }
  2592. else {
  2593. $sPostType = 'common';
  2594. $iSenderId = $iObjectAuthorId = (int)$aEvent['object_id'];
  2595. }
  2596. //--- Event -> Fail for Alerts Engine ---//
  2597. bx_alert($this->_oConfig->getObject('alert'), 'fail_' . $sPostType, $iContentId, $iSenderId, array(
  2598. 'owner_id' => $aEvent['owner_id'],
  2599. 'object_author_id' => $iObjectAuthorId,
  2600. 'privacy_view' => $aEvent['object_privacy_view'],
  2601. ));
  2602. //--- Event -> Post for Alerts Engine ---//
  2603. }
  2604. public function onRepost($iContentId, $aReposted = array())
  2605. {
  2606. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2607. if(empty($aReposted)) {
  2608. $aContent = unserialize($aEvent['content']);
  2609. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  2610. if(empty($aReposted) || !is_array($aReposted))
  2611. return;
  2612. }
  2613. $iUserId = $this->getUserId();
  2614. $this->_oDb->insertRepostTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aReposted['id']);
  2615. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts']);
  2616. //--- Timeline -> Update for Alerts Engine ---//
  2617. bx_alert($this->_oConfig->getObject('alert'), 'repost', $aReposted['id'], $iUserId, array(
  2618. 'privacy_view' => $aEvent['object_privacy_view'],
  2619. 'object_author_id' => $aReposted['owner_id'],
  2620. 'repost_id' => $iContentId,
  2621. ));
  2622. //--- Timeline -> Update for Alerts Engine ---//
  2623. }
  2624. public function onDelete($aEvent)
  2625. {
  2626. $CNF = &$this->_oConfig->CNF;
  2627. $iUserId = $this->getUserId();
  2628. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  2629. $sCommonPostComment = $this->_oConfig->getObject('comment');
  2630. //--- Delete comments for Common posts.
  2631. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  2632. $oComments = $this->getCmtsObject($sCommonPostComment, $aEvent[$CNF['FIELD_ID']]);
  2633. if($oComments !== false)
  2634. $oComments->onObjectDelete($aEvent[$CNF['FIELD_ID']]);
  2635. }
  2636. //--- Delete attached photos, videos and links when common event was deleted.
  2637. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  2638. $this->_deleteMedia(BX_TIMELINE_MEDIA_PHOTO, $aEvent[$CNF['FIELD_ID']]);
  2639. $this->_deleteMedia(BX_TIMELINE_MEDIA_VIDEO, $aEvent[$CNF['FIELD_ID']]);
  2640. $this->_deleteLinks($aEvent[$CNF['FIELD_ID']]);
  2641. }
  2642. //--- Update parent event when repost event was deleted.
  2643. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  2644. if($bRepost) {
  2645. $this->_oDb->deleteRepostTrack($aEvent[$CNF['FIELD_ID']]);
  2646. $aContent = unserialize($aEvent['content']);
  2647. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  2648. if(!empty($aReposted) && is_array($aReposted))
  2649. $this->_oDb->updateRepostCounter($aReposted[$CNF['FIELD_ID']], $aReposted['reposts'], -1);
  2650. }
  2651. //--- Find and delete repost events when parent event was deleted.
  2652. $bSystem = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']);
  2653. $aRepostEvents = $this->_oDb->getEvents(array('browse' => 'reposted_by_descriptor', 'type' => $aEvent['type']));
  2654. foreach($aRepostEvents as $aRepostEvent) {
  2655. $aContent = unserialize($aRepostEvent['content']);
  2656. 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[$CNF['FIELD_ID']])) && (int)$this->_oDb->deleteEvent(array('id' => (int)$aRepostEvent[$CNF['FIELD_ID']])) > 0) {
  2657. $oComments = $this->getCmtsObject($sCommonPostComment, $aRepostEvent[$CNF['FIELD_ID']]);
  2658. if($oComments !== false)
  2659. $oComments->onObjectDelete($aRepostEvent[$CNF['FIELD_ID']]);
  2660. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aEvent[$CNF['FIELD_ID']], $iUserId, array(
  2661. 'repost_id' => $aRepostEvent[$CNF['FIELD_ID']],
  2662. ));
  2663. }
  2664. }
  2665. //--- Delete associated meta.
  2666. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  2667. $oMetatags->onDeleteContent($aEvent[$CNF['FIELD_ID']]);
  2668. //--- Delete feed cache.
  2669. $this->_oDb->deleteCache(array('event_id' => $aEvent[$CNF['FIELD_ID']]));
  2670. //--- Delete item cache.
  2671. $sCacheItemKey = $this->_oConfig->getCacheItemKey($aEvent[$CNF['FIELD_ID']]);
  2672. $this->getCacheItemObject()->delData($sCacheItemKey);
  2673. //--- Event -> Delete for Alerts Engine ---//
  2674. if($bRepost)
  2675. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aReposted[$CNF['FIELD_ID']], $iUserId, array(
  2676. 'repost_id' => $aEvent[$CNF['FIELD_ID']],
  2677. ));
  2678. else
  2679. bx_alert($this->_oConfig->getObject('alert'), 'delete', $aEvent[$CNF['FIELD_ID']], $iUserId);
  2680. //--- Event -> Delete for Alerts Engine ---//
  2681. }
  2682. public function getParams($sView = '', $sType = '', $iOwnerId = 0, $iStart = 0, $iPerPage = 0, $sFilter = BX_TIMELINE_FILTER_ALL, $aModules = array(), $iTimeline = 0)
  2683. {
  2684. return $this->_prepareParams(array(
  2685. 'view' => $sView,
  2686. 'type' => $sType,
  2687. 'owner_id' => $iOwnerId,
  2688. 'start' => $iStart,
  2689. 'per_page' => $iPerPage,
  2690. 'timeline' => $iTimeline,
  2691. 'filter' => $sFilter,
  2692. 'modules' => $aModules
  2693. ));
  2694. }
  2695. public function getParamsExt($aParams = array())
  2696. {
  2697. return $this->_prepareParams($aParams);
  2698. }
  2699. public function getViewsData(&$aViews)
  2700. {
  2701. if(empty($aViews) || !is_array($aViews))
  2702. return false;
  2703. $sSystem = isset($aViews['system']) ? $aViews['system'] : '';
  2704. $iObjectId = isset($aViews['object_id']) ? (int)$aViews['object_id'] : 0;
  2705. $iCount = isset($aViews['count']) ? (int)$aViews['count'] : 0;
  2706. if($sSystem == '' || $iObjectId == 0)
  2707. return false;
  2708. return array($sSystem, $iObjectId, $iCount);
  2709. }
  2710. public function getVotesData(&$aVotes)
  2711. {
  2712. if(empty($aVotes) || !is_array($aVotes))
  2713. return false;
  2714. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  2715. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  2716. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  2717. if($sSystem == '' || $iObjectId == 0)
  2718. return false;
  2719. return array($sSystem, $iObjectId, $iCount);
  2720. }
  2721. public function getReactionsData(&$aReactions)
  2722. {
  2723. if(empty($aReactions) || !is_array($aReactions))
  2724. return false;
  2725. $sSystem = isset($aReactions['system']) ? $aReactions['system'] : '';
  2726. $iObjectId = isset($aReactions['object_id']) ? (int)$aReactions['object_id'] : 0;
  2727. $iCount = isset($aReactions['count']) ? (int)$aReactions['count'] : 0;
  2728. if($sSystem == '' || $iObjectId == 0)
  2729. return false;
  2730. return array($sSystem, $iObjectId, $iCount);
  2731. }
  2732. public function getScoresData(&$aScores)
  2733. {
  2734. if(empty($aScores) || !is_array($aScores))
  2735. return false;
  2736. $sSystem = isset($aScores['system']) ? $aScores['system'] : '';
  2737. $iObjectId = isset($aScores['object_id']) ? (int)$aScores['object_id'] : 0;
  2738. $iScore = isset($aScores['score']) ? (int)$aScores['score'] : 0;
  2739. if($sSystem == '' || $iObjectId == 0)
  2740. return false;
  2741. return array($sSystem, $iObjectId, $iScore);
  2742. }
  2743. public function getReportsData(&$aReports)
  2744. {
  2745. if(empty($aReports) || !is_array($aReports))
  2746. return false;
  2747. $sSystem = isset($aReports['system']) ? $aReports['system'] : '';
  2748. $iObjectId = isset($aReports['object_id']) ? (int)$aReports['object_id'] : 0;
  2749. $iCount = isset($aReports['count']) ? (int)$aReports['count'] : 0;
  2750. if($sSystem == '' || $iObjectId == 0)
  2751. return false;
  2752. return array($sSystem, $iObjectId, $iCount);
  2753. }
  2754. public function getCommentsData(&$aComments)
  2755. {
  2756. if(empty($aComments) || !is_array($aComments))
  2757. return false;
  2758. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  2759. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  2760. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  2761. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  2762. return false;
  2763. return array($sSystem, $iObjectId, $iCount);
  2764. }
  2765. public function getUserInfo($iUserId = 0)
  2766. {
  2767. $iLoggedId = $this->getUserId();
  2768. $iUserId = (int)$iUserId;
  2769. return parent::getUserInfo($iUserId);
  2770. }
  2771. /**
  2772. * Protected Methods
  2773. */
  2774. protected function _serviceGetBlockView($iProfileId = 0, $aBrowseParams = array())
  2775. {
  2776. if(empty($iProfileId) && bx_get('profile_id') !== false)
  2777. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  2778. if(empty($iProfileId) && isLogged())
  2779. $iProfileId = bx_get_logged_profile_id();
  2780. $aBrowseParams['owner_id'] = $iProfileId;
  2781. $aBlock = $this->_getBlockView($aBrowseParams);
  2782. if(!empty($aBlock))
  2783. return $aBlock;
  2784. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  2785. }
  2786. protected function _serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $aBrowseParams = array())
  2787. {
  2788. if(empty($sProfileModule))
  2789. return array();
  2790. if(empty($iProfileContentId) && bx_get('id') !== false)
  2791. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2792. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  2793. if(empty($oProfile))
  2794. return array();
  2795. $aBrowseParams['owner_id'] = $oProfile->id();
  2796. return $this->_getBlockView($aBrowseParams);
  2797. }
  2798. protected function _serviceGetBlockViewHome($aBrowseParams = array())
  2799. {
  2800. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  2801. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_home'), $sRssUrl);
  2802. return $this->_serviceGetBlockViewByType($aBrowseParams);
  2803. }
  2804. protected function _serviceGetBlockViewHot($aBrowseParams = array())
  2805. {
  2806. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  2807. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_hot'), $sRssUrl);
  2808. return $this->_serviceGetBlockViewByType($aBrowseParams);
  2809. }
  2810. protected function _serviceGetBlockViewByType($aBrowseParams = array())
  2811. {
  2812. $aParams = $this->_prepareParams($aBrowseParams);
  2813. $this->_iOwnerId = $aParams['owner_id'];
  2814. return array(
  2815. 'content' => $this->_oTemplate->getViewBlock($aParams)
  2816. );
  2817. }
  2818. protected function _getBlockPost($iProfileId, $aParams = array())
  2819. {
  2820. $this->_iOwnerId = $iProfileId;
  2821. if($this->isAllowedPost() !== true)
  2822. return array();
  2823. return array(
  2824. 'content' => $this->_oTemplate->getPostBlock($this->_iOwnerId, $aParams)
  2825. );
  2826. }
  2827. protected function _getBlockView($aBrowseParams = array())
  2828. {
  2829. if(empty($aBrowseParams['owner_id']))
  2830. return array();
  2831. $aParams = $this->_prepareParams($aBrowseParams);
  2832. if(empty($aParams['per_page']))
  2833. $aParams['per_page'] = $this->_oConfig->getPerPage('profile');
  2834. $this->_iOwnerId = $aParams['owner_id'];
  2835. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  2836. $mixedResult = $oProfileOwner->checkAllowedProfileView();
  2837. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  2838. return array('content' => MsgBox($mixedResult));
  2839. list($sUserName) = $this->getUserInfo($aParams['owner_id']);
  2840. $sView = $aParams['view'];
  2841. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_OWNER . '/' . $this->_iOwnerId . '/';
  2842. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  2843. $aMenu = array(
  2844. 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),
  2845. 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)),
  2846. 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')),
  2847. array('id' => $sView . '-get-rss', 'name' => $sView . '-get-rss', 'class' => '', 'link' => $sRssUrl, 'onclick' => '', 'target' => '_blank', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  2848. );
  2849. $sContent = '';
  2850. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view', $this->_iOwnerId, $this->getUserId(), array('override_content' => &$sContent, 'params' => &$aParams, 'menu' => &$aMenu));
  2851. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $sView . '-view-all', 'menu_items' => $aMenu));
  2852. $oMenu->setSelected('', $sView . '-view-all');
  2853. if (!$sContent)
  2854. $sContent = $this->_oTemplate->getViewBlock($aParams);
  2855. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view'), $sRssUrl);
  2856. return array('content' => $sContent, 'menu' => $oMenu);
  2857. }
  2858. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  2859. {
  2860. $CNF = &$this->_oConfig->CNF;
  2861. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  2862. $sText = '';
  2863. if(isset($aContentInfo['content'])){
  2864. $aTmp = unserialize($aContentInfo['content']);
  2865. if(isset($aTmp['text']))
  2866. $sText = $aTmp['text'];
  2867. }
  2868. if(empty($sText) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  2869. $sText = $aContentInfo[$CNF['FIELD_TITLE']];
  2870. if(!empty($CNF['OBJECT_METATAGS']) && !empty($sText)) {
  2871. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  2872. $sText = $oMetatags->metaParse($aContentInfo[$CNF['FIELD_ID']], $sText);
  2873. }
  2874. return array(
  2875. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  2876. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  2877. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  2878. 'url' => $sUrl,
  2879. 'title' => '',
  2880. 'text' => $sText,
  2881. 'images' => array(),
  2882. 'videos' => array()
  2883. );
  2884. }
  2885. protected function _isAllowedPin($aEvent, $bPerform = false)
  2886. {
  2887. $iUserId = (int)$this->getUserId();
  2888. if($iUserId == 0)
  2889. return false;
  2890. if(isAdmin() || (int)$aEvent['owner_id'] == $iUserId || ((int)$aEvent['owner_id'] == 0 && $this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && (int)$aEvent['object_id'] == $iUserId))
  2891. return true;
  2892. $aCheckResult = checkActionModule($iUserId, 'pin', $this->getName(), $bPerform);
  2893. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2894. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_pin', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2895. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2896. }
  2897. protected function _isAllowedStick($aEvent, $bPerform = false)
  2898. {
  2899. $iUserId = (int)$this->getUserId();
  2900. if($iUserId == 0)
  2901. return false;
  2902. if(isAdmin())
  2903. return true;
  2904. $aCheckResult = checkActionModule($iUserId, 'stick', $this->getName(), $bPerform);
  2905. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2906. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_stick', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2907. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2908. }
  2909. protected function _isAllowedPromote($aEvent, $bPerform = false)
  2910. {
  2911. if(isAdmin())
  2912. return true;
  2913. $iUserId = (int)$this->getUserId();
  2914. if($iUserId == 0)
  2915. return false;
  2916. $aCheckResult = checkActionModule($iUserId, 'promote', $this->getName(), $bPerform);
  2917. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2918. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_promote', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2919. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2920. }
  2921. protected function _addLink(&$oForm)
  2922. {
  2923. $iUserId = $this->getUserId();
  2924. $sLink = $oForm->getCleanValue('url');
  2925. $aMatches = array();
  2926. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  2927. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  2928. $aSiteInfo = bx_get_site_info($sLink, array(
  2929. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  2930. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  2931. ));
  2932. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : _t('_Empty');
  2933. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : _t('_Empty');
  2934. $sMediaUrl = '';
  2935. if(!empty($aSiteInfo['thumbnailUrl']))
  2936. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  2937. else if(!empty($aSiteInfo['OGImage']))
  2938. $sMediaUrl = $aSiteInfo['OGImage'];
  2939. $iMediaId = 0;
  2940. $oStorage = null;
  2941. if(!empty($sMediaUrl)) {
  2942. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . BX_TIMELINE_MEDIA_PHOTO . 's'));
  2943. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  2944. }
  2945. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  2946. if(!empty($iId)) {
  2947. if(!empty($oStorage) && !empty($iMediaId))
  2948. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  2949. return array('id' => $iId, 'item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId));
  2950. }
  2951. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  2952. }
  2953. protected function _deleteLinks($iId)
  2954. {
  2955. $aLinks = $this->_oDb->getLinks($iId);
  2956. if(empty($aLinks) || !is_array($aLinks))
  2957. return;
  2958. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  2959. foreach($aLinks as $aLink)
  2960. if(!empty($aLink['media_id']))
  2961. $oStorage->deleteFile($aLink['media_id']);
  2962. $this->_oDb->deleteLinks($iId);
  2963. }
  2964. protected function _saveMedia($sType, $iId, $aItemIds)
  2965. {
  2966. if(empty($aItemIds) || !is_array($aItemIds))
  2967. return;
  2968. $iUserId = $this->getUserId();
  2969. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  2970. foreach($aItemIds as $iItemId)
  2971. if($this->_oDb->saveMedia($sType, $iId, $iItemId))
  2972. $oStorage->afterUploadCleanup($iItemId, $iUserId);
  2973. }
  2974. protected function _deleteMedia($sType, $iId)
  2975. {
  2976. $aItems = $this->_oDb->getMedia($sType, $iId);
  2977. if(empty($aItems) || !is_array($aItems))
  2978. return;
  2979. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  2980. foreach($aItems as $iItemId)
  2981. $oStorage->deleteFile($iItemId);
  2982. $this->_oDb->deleteMedia($sType, $iId);
  2983. }
  2984. protected function _prepareParams($aParams)
  2985. {
  2986. if(empty($aParams['name']))
  2987. $aParams['name'] = '';
  2988. if(empty($aParams['view']))
  2989. $aParams['view'] = BX_TIMELINE_VIEW_DEFAULT;
  2990. if(empty($aParams['type']))
  2991. $aParams['type'] = BX_TIMELINE_TYPE_DEFAULT;
  2992. if(empty($aParams['owner_id']))
  2993. $aParams['owner_id'] = $this->getUserId();
  2994. if(!isset($aParams['start']) || (int)$aParams['start'] < 0)
  2995. $aParams['start'] = 0;
  2996. if(!isset($aParams['per_page']) || (int)$aParams['per_page'] <= 0)
  2997. $aParams['per_page'] = isset($aParams['per_page_default']) && (int)$aParams['per_page_default'] > 0 ? $aParams['per_page_default'] : $this->_oConfig->getPerPage();
  2998. if(empty($aParams['timeline']) || (int)$aParams['timeline'] < 0)
  2999. $aParams['timeline'] = 0;
  3000. if(empty($aParams['filter']))
  3001. $aParams['filter'] = BX_TIMELINE_FILTER_ALL;
  3002. if(empty($aParams['modules']) || !is_array($aParams['modules']))
  3003. $aParams['modules'] = array();
  3004. if(empty($aParams['blink']) || !is_array($aParams['blink']))
  3005. $aParams['blink'] = array();
  3006. if($this->_oConfig->isHot())
  3007. $aParams['hot'] = $this->_oDb->getHot();
  3008. $aParams = array_merge($aParams, array(
  3009. 'browse' => 'list',
  3010. 'status' => BX_TIMELINE_STATUS_ACTIVE
  3011. ));
  3012. return $aParams;
  3013. }
  3014. protected function _prepareParamsGet()
  3015. {
  3016. $aParams = array();
  3017. $aParams['name'] = bx_get('name');
  3018. $aParams['name'] = $aParams['name'] !== false ? bx_process_input($aParams['name'], BX_DATA_TEXT) : '';
  3019. $aParams['view'] = bx_get('view');
  3020. $aParams['view'] = $aParams['view'] !== false ? bx_process_input($aParams['view'], BX_DATA_TEXT) : BX_TIMELINE_VIEW_DEFAULT;
  3021. $aParams['type'] = bx_get('type');
  3022. $aParams['type'] = $aParams['type'] !== false ? bx_process_input($aParams['type'], BX_DATA_TEXT) : BX_TIMELINE_TYPE_DEFAULT;
  3023. $aParams['owner_id'] = bx_get('owner_id');
  3024. $aParams['owner_id'] = $aParams['owner_id'] !== false ? bx_process_input($aParams['owner_id'], BX_DATA_INT) : $this->getUserId();
  3025. $aParams['start'] = bx_get('start');
  3026. $aParams['start'] = $aParams['start'] !== false ? bx_process_input($aParams['start'], BX_DATA_INT) : 0;
  3027. $aParams['per_page'] = bx_get('per_page');
  3028. $aParams['per_page'] = $aParams['per_page'] !== false ? bx_process_input($aParams['per_page'], BX_DATA_INT) : $this->_oConfig->getPerPage();
  3029. $aParams['timeline'] = bx_get('timeline');
  3030. $aParams['timeline'] = $aParams['timeline'] !== false ? bx_process_input($aParams['timeline'], BX_DATA_INT) : 0;
  3031. $aParams['filter'] = bx_get('filter');
  3032. $aParams['filter'] = $aParams['filter'] !== false ? bx_process_input($aParams['filter'], BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  3033. $aParams['modules'] = bx_get('modules');
  3034. $aParams['modules'] = $aParams['modules'] !== false ? bx_process_input($aParams['modules'], BX_DATA_TEXT) : array();
  3035. $aParams['blink'] = bx_get('blink');
  3036. $aParams['blink'] = $aParams['blink'] !== false ? explode(',', bx_process_input($aParams['blink'], BX_DATA_TEXT)) : array();
  3037. if($this->_oConfig->isHot())
  3038. $aParams['hot'] = $this->_oDb->getHot();
  3039. $aParams = array_merge($aParams, array(
  3040. 'browse' => 'list',
  3041. 'status' => BX_TIMELINE_STATUS_ACTIVE,
  3042. 'dynamic_mode' => true,
  3043. ));
  3044. return $aParams;
  3045. }
  3046. protected function _prepareTextForSave($s)
  3047. {
  3048. return bx_process_input($s, BX_DATA_HTML);
  3049. }
  3050. protected function _getFieldValue($sField, $iContentId)
  3051. {
  3052. $CNF = &$this->_oConfig->CNF;
  3053. if(empty($CNF[$sField]))
  3054. return false;
  3055. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  3056. if(empty($aEvent) || empty($aEvent[$CNF[$sField]]))
  3057. return false;
  3058. return $aEvent[$CNF[$sField]];
  3059. }
  3060. /**
  3061. * Returns records for React Jot using OAuth2
  3062. * @param int $iProfileId
  3063. * @param string $sPage
  3064. * @param string $sTab
  3065. * @param int $iStart
  3066. * @param int $iPerPage
  3067. * @return array
  3068. */
  3069. public function serviceGetUserPosts($iProfileId = 0, $sPage = 'home', $sTab = 'hot', $iStart = 0, $iPerPage = 0)
  3070. {
  3071. $iProfileId = (int)$iProfileId ? (int)$iProfileId : bx_get_logged_profile_id();
  3072. if(empty($iProfileId))
  3073. return array(
  3074. 'code' => 1,
  3075. 'result' => array(),
  3076. 'message' => _t('_bx_timeline_txt_msg_no_profile_id'),
  3077. 'page' => $sPage,
  3078. 'tab' => $sTab
  3079. );
  3080. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  3081. $sView = BX_TIMELINE_VIEW_DEFAULT;
  3082. $sFilter = BX_TIMELINE_FILTER_ALL;
  3083. $aModules = array();
  3084. switch($sPage){
  3085. case 'profile':
  3086. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  3087. $sFilter = BX_TIMELINE_FILTER_OWNER;
  3088. break;
  3089. default:
  3090. if ($this -> _oDb -> isModuleByName($sPage))
  3091. $aModules = array($sPage);
  3092. }
  3093. switch($sTab)
  3094. {
  3095. case 'latest':
  3096. $sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  3097. break;
  3098. case 'popular':
  3099. $sType = BX_TIMELINE_TYPE_HOT;
  3100. break;
  3101. case 'feed':
  3102. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  3103. break;
  3104. default:
  3105. if ($this -> _oDb -> isModuleByName($sTab))
  3106. $aModules = array($sTab);
  3107. }
  3108. $aParams = $this->getParams($sView, $sType, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules);
  3109. $aData = $this->_oDb->getEvents($aParams, true);
  3110. list($aEvents, $iCount) = $aData;
  3111. if(empty($aEvents) || !is_array($aEvents))
  3112. return array(
  3113. 'code' => 0,
  3114. 'result' => array(),
  3115. 'message' => _t('_bx_timeline_txt_msg_no_results'),
  3116. 'page' => $sPage,
  3117. 'tab' => $sTab
  3118. );
  3119. $aBrowseParams = array();
  3120. $aItems = array();
  3121. foreach($aEvents as $aEvent) {
  3122. $aResult = $this->_oTemplate->getData($aEvent, $aBrowseParams);
  3123. if($aResult === false)
  3124. continue;
  3125. $oOwnerProfile = BxDolProfile::getInstance($aResult['owner_id']);
  3126. $aFiles = array();
  3127. $aContent = &$aResult['content'];
  3128. if (!empty($aContent['image']))
  3129. $aFiles['images'] = array_values($aContent['images']);
  3130. if (!empty($aContent['images_attach']))
  3131. $aFiles['images'] = array_values($aContent['images_attach']);
  3132. if (!empty($aContent['videos']))
  3133. $aFiles['videos'] = array_values($aContent['videos']);
  3134. else
  3135. if (!empty($aContent['videos_attach']))
  3136. $aFiles['videos'] = array_values($aContent['videos_attach']);
  3137. if (!empty($aContent['files']))
  3138. $aFiles['files'] = array_values($aContent['files']);
  3139. else
  3140. if (!empty($aContent['files_attach']))
  3141. $aFiles['files'] = array_values($aContent['files_attach']);
  3142. $aItems[$aEvent['id']] = array_merge(array(
  3143. 'owner' => array(
  3144. 'icon' => $oOwnerProfile -> getThumb(),
  3145. 'name' => $oOwnerProfile -> getDisplayName(),
  3146. 'url' => $oOwnerProfile -> getUrl()
  3147. ),
  3148. 'sample' => !empty($aResult['sample']) ? _t($aResult['sample']) : _t('_bx_timeline_txt_sample'),
  3149. 'sample_action' => !empty($aResult['sample_action']) ? _t($aResult['sample_action']) : _t('_bx_timeline_txt_added_sample'),
  3150. 'url' => isset($aResult['url']) ? $aResult['url'] : '',
  3151. 'raw' => isset($aContent['raw']) ? strip_tags($aContent['raw']) : '',
  3152. 'text' => isset($aContent['text']) ? strip_tags($aContent['text']) : '',
  3153. 'views' => isset($aResult['views']['count']) ? (int)$aResult['views']['count'] : 0,
  3154. 'votes' => isset($aResult['votes']['count']) ? (int)$aResult['votes']['count'] : 0,
  3155. 'reactions' => isset($aResult['reactions']['count']) ? (int)$aResult['reactions']['count'] : 0,
  3156. 'scores' => isset($aResult['scores']['count']) ? (int)$aResult['scores']['count'] : 0,
  3157. 'reports' => isset($aResult['reports']['count']) ? (int)$aResult['reports']['count'] : 0,
  3158. 'comments' => isset($aResult['comments']['count']) ? (int)$aResult['comments']['count'] : 0,
  3159. 'date' => isset($aResult['date']) ? $aResult['date'] : $aEvent['date'],
  3160. 'type' => stripos($aEvent['type'], 'timeline') !== FALSE ? 'bx_timeline' : $aEvent['type'],
  3161. 'event_type' => $aEvent['type'],
  3162. 'id' => $aEvent['id'],
  3163. 'content' => $aResult['content'],
  3164. 'title' => isset($aResult['title']) ? _t($aResult['title']) : '',
  3165. 'description' => isset($aResult['description']) ? $aResult['description'] : ''
  3166. ), $aFiles);
  3167. }
  3168. return array(
  3169. 'result' => $aItems,
  3170. 'code' => 0,
  3171. 'message' => '',
  3172. 'page' => $sPage,
  3173. 'tab' => $sTab,
  3174. 'total' => $iCount,
  3175. 'start' => (int)$iStart
  3176. );
  3177. }
  3178. }
  3179. /** @} */