BxTimelineModule.php 128 KB

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