BxTimelineModule.php 125 KB

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