BxTimelineModule.php 124 KB

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