BxTimelineModule.php 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282
  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. if($this->_oConfig->isSystem($aContent['type'], $aContent['action']))
  1274. $iEntryAuthor = (int)$aContent['owner_id'];
  1275. else
  1276. $iEntryAuthor = (int)$aContent['object_id'];
  1277. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : $this->_oConfig->getTitle($aContent['description'], $aContent['object_id']);
  1278. return array(
  1279. 'entry_sample' => $CNF['T']['txt_sample_single_ext'],
  1280. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1281. 'entry_caption' => $sEntryCaption,
  1282. 'entry_author' => $iEntryAuthor,
  1283. 'lang_key' => '' //may be empty or not specified. In this case the default one from Notification module will be used.
  1284. );
  1285. }
  1286. /**
  1287. * @page service Service Calls
  1288. * @section bx_timeline Timeline
  1289. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1290. * @subsubsection bx_timeline-get_notifications_comment get_notifications_comment
  1291. *
  1292. * @code bx_srv('bx_timeline', 'get_notifications_comment', [...]); @endcode
  1293. *
  1294. * Get data for Post Comment event to display in Notifications module.
  1295. *
  1296. * @param $aEvent an array with event description.
  1297. * @return an array with special format.
  1298. *
  1299. * @see BxTimelineModule::serviceGetNotificationsComment
  1300. */
  1301. /**
  1302. * @ref bx_timeline-get_notifications_comment "get_notifications_comment"
  1303. */
  1304. public function serviceGetNotificationsComment($aEvent)
  1305. {
  1306. $CNF = &$this->_oConfig->CNF;
  1307. $iContent = (int)$aEvent['object_id'];
  1308. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1309. if(empty($aContent) || !is_array($aContent))
  1310. return array();
  1311. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContent);
  1312. if(!$oComment || !$oComment->isEnabled())
  1313. return array();
  1314. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : $this->_oConfig->getTitle($aContent['description'], $aContent['object_id']);
  1315. return array(
  1316. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1317. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1318. 'entry_caption' => $sEntryCaption,
  1319. 'entry_author' => $aContent['owner_id'],
  1320. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  1321. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  1322. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1323. );
  1324. }
  1325. /**
  1326. * @page service Service Calls
  1327. * @section bx_timeline Timeline
  1328. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1329. * @subsubsection bx_timeline-get_notifications_vote get_notifications_vote
  1330. *
  1331. * @code bx_srv('bx_timeline', 'get_notifications_vote', [...]); @endcode
  1332. *
  1333. * Get data for Vote event to display in Notifications module.
  1334. *
  1335. * @param $aEvent an array with event description.
  1336. * @return an array with special format.
  1337. *
  1338. * @see BxTimelineModule::serviceGetNotificationsVote
  1339. */
  1340. /**
  1341. * @ref bx_timeline-get_notifications_vote "get_notifications_vote"
  1342. */
  1343. public function serviceGetNotificationsVote($aEvent)
  1344. {
  1345. $CNF = &$this->_oConfig->CNF;
  1346. $iContent = (int)$aEvent['object_id'];
  1347. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1348. if(empty($aContent) || !is_array($aContent))
  1349. return array();
  1350. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContent);
  1351. if(!$oVote || !$oVote->isEnabled())
  1352. return array();
  1353. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : $this->_oConfig->getTitle($aContent['description'], $aContent['object_id']);
  1354. return array(
  1355. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1356. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1357. 'entry_caption' => $sEntryCaption,
  1358. 'entry_author' => $aContent['owner_id'],
  1359. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  1360. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1361. );
  1362. }
  1363. /**
  1364. * @page service Service Calls
  1365. * @section bx_timeline Timeline
  1366. * @subsection bx_timeline-repost Repost
  1367. * @subsubsection bx_timeline-get_repost_element_block get_repost_element_block
  1368. *
  1369. * @code bx_srv('bx_timeline', 'get_repost_element_block', [...]); @endcode
  1370. *
  1371. * Get repost element for content based modules.
  1372. *
  1373. * @param $iOwnerId integer value with owner profile ID.
  1374. * @param $sType string value with type (module name).
  1375. * @param $sAction string value with action (module action).
  1376. * @param $iObjectId integer value with object ID to be reposted.
  1377. * @param $aParams (optional) an array with additional params.
  1378. * @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.
  1379. *
  1380. * @see BxTimelineModule::serviceGetRepostElementBlock
  1381. */
  1382. /**
  1383. * @ref bx_timeline-get_repost_element_block "get_repost_element_block"
  1384. */
  1385. public function serviceGetRepostElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
  1386. {
  1387. if(!$this->isEnabled())
  1388. return '';
  1389. $aParams = array_merge($this->_oConfig->getRepostDefaults(), $aParams);
  1390. return $this->_oTemplate->getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
  1391. }
  1392. /**
  1393. * @page service Service Calls
  1394. * @section bx_timeline Timeline
  1395. * @subsection bx_timeline-repost Repost
  1396. * @subsubsection bx_timeline-get_repost_counter get_repost_counter
  1397. *
  1398. * @code bx_srv('bx_timeline', 'get_repost_counter', [...]); @endcode
  1399. *
  1400. * Get repost counter.
  1401. *
  1402. * @param $sType string value with type (module name).
  1403. * @param $sAction string value with action (module action).
  1404. * @param $iObjectId integer value with object ID to be reposted.
  1405. * @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.
  1406. *
  1407. * @see BxTimelineModule::serviceGetRepostCounter
  1408. */
  1409. /**
  1410. * @ref bx_timeline-get_repost_counter "get_repost_counter"
  1411. */
  1412. public function serviceGetRepostCounter($sType, $sAction, $iObjectId)
  1413. {
  1414. if(!$this->isEnabled())
  1415. return '';
  1416. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1417. return $this->_oTemplate->getRepostCounter($aReposted);
  1418. }
  1419. /**
  1420. * @page service Service Calls
  1421. * @section bx_timeline Timeline
  1422. * @subsection bx_timeline-repost Repost
  1423. * @subsubsection bx_timeline-get_repost_js_script get_repost_js_script
  1424. *
  1425. * @code bx_srv('bx_timeline', 'get_repost_js_script', [...]); @endcode
  1426. *
  1427. * Get repost JavaScript code.
  1428. *
  1429. * @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.
  1430. *
  1431. * @see BxTimelineModule::serviceGetRepostJsScript
  1432. */
  1433. /**
  1434. * @ref bx_timeline-get_repost_js_script "get_repost_js_script"
  1435. */
  1436. public function serviceGetRepostJsScript()
  1437. {
  1438. if(!$this->isEnabled())
  1439. return '';
  1440. return $this->_oTemplate->getRepostJsScript();
  1441. }
  1442. /**
  1443. * @page service Service Calls
  1444. * @section bx_timeline Timeline
  1445. * @subsection bx_timeline-repost Repost
  1446. * @subsubsection bx_timeline-get_repost_js_click get_repost_js_click
  1447. *
  1448. * @code bx_srv('bx_timeline', 'get_repost_js_click', [...]); @endcode
  1449. *
  1450. * Get repost JavaScript code for OnClick event.
  1451. *
  1452. * @param $iOwnerId integer value with owner profile ID.
  1453. * @param $sType string value with type (module name).
  1454. * @param $sAction string value with action (module action).
  1455. * @param $iObjectId integer value with object ID to be reposted.
  1456. * @return HTML string with JavaScript code to display in OnClick events of HTML elements.
  1457. *
  1458. * @see BxTimelineModule::serviceGetRepostJsClick
  1459. */
  1460. /**
  1461. * @ref bx_timeline-get_repost_js_click "get_repost_js_click"
  1462. */
  1463. public function serviceGetRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  1464. {
  1465. if(!$this->isEnabled())
  1466. return '';
  1467. return $this->_oTemplate->getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  1468. }
  1469. /**
  1470. * @page service Service Calls
  1471. * @section bx_timeline Timeline
  1472. * @subsection bx_timeline-repost Repost
  1473. * @subsubsection bx_timeline-repost repost
  1474. *
  1475. * @code bx_srv('bx_timeline', 'repost', [...]); @endcode
  1476. *
  1477. * Perform repost action.
  1478. *
  1479. * @param $iAuthorId integer value with performer profile ID.
  1480. * @param $iOwnerId integer value with repost event owner profile ID.
  1481. * @param $sType string value with type (module name).
  1482. * @param $sAction string value with action (module action).
  1483. * @param $iObjectId integer value with object ID to be reposted.
  1484. * @parem $bForce boolean value force reposting without ACL check.
  1485. * @return an array with error (code and message) or integer with newly created repost event ID.
  1486. *
  1487. * @see BxTimelineModule::serviceRepost
  1488. */
  1489. /**
  1490. * @ref bx_timeline-repost "repost"
  1491. */
  1492. public function serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $bForce = false)
  1493. {
  1494. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1495. if(empty($aReposted) || !is_array($aReposted))
  1496. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1497. $mixedAllowed = $this->isAllowedRepost($aReposted, true);
  1498. if(!$bForce && $mixedAllowed !== true)
  1499. return array('code' => 2, 'message' => strip_tags($mixedAllowed));
  1500. $bReposted = $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $iAuthorId);
  1501. if($bReposted)
  1502. return array('code' => 3, 'message' => _t('_bx_timeline_txt_err_already_reposted'));
  1503. $iId = $this->_oDb->insertEvent(array(
  1504. 'owner_id' => $iOwnerId,
  1505. 'type' => $this->_oConfig->getPrefix('common_post') . 'repost',
  1506. 'action' => '',
  1507. 'object_id' => $iAuthorId,
  1508. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault('object'),
  1509. 'content' => serialize(array(
  1510. 'type' => $sType,
  1511. 'action' => $sAction,
  1512. 'object_id' => $iObjectId,
  1513. )),
  1514. 'title' => '',
  1515. 'description' => ''
  1516. ));
  1517. if(empty($iId))
  1518. return array('code' => 4, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1519. $this->onRepost($iId, $aReposted);
  1520. return $iId;
  1521. }
  1522. /**
  1523. * @page service Service Calls
  1524. * @section bx_timeline Timeline
  1525. * @subsection bx_timeline-repost Repost
  1526. * @subsubsection bx_timeline-repost_by_id repost_by_id
  1527. *
  1528. * @code bx_srv('bx_timeline', 'repost_by_id', [...]); @endcode
  1529. *
  1530. * Perform repost action by Timeline event ID.
  1531. *
  1532. * @param $iAuthorId integer value with performer profile ID.
  1533. * @param $iOwnerId integer value with repost event owner profile ID.
  1534. * @param $iEventId integer value with event ID which will be reposted.
  1535. * @parem $bForce boolean value force reposting without ACL check.
  1536. * @return an array with error (code and message) or integer with newly created repost event ID.
  1537. *
  1538. * @see BxTimelineModule::serviceRepostById
  1539. */
  1540. /**
  1541. * @ref bx_timeline-repost_by_id "repost_by_id"
  1542. */
  1543. public function serviceRepostById($iAuthorId, $iOwnerId, $iEventId, $bForce = false)
  1544. {
  1545. $aEvent = $this->_oDb->getEntriesBy(array('type' => 'id', 'id' => $iEventId));
  1546. if(empty($aEvent) || !is_array($aEvent))
  1547. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1548. $sType = $aEvent['type'];
  1549. $sAction = $aEvent['action'];
  1550. $iObjectId = $this->_oConfig->isSystem($sType, $sAction) ? $aEvent['object_id'] : $aEvent['id'];
  1551. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  1552. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  1553. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1554. if(empty($aReposted) || !is_array($aReposted))
  1555. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1556. $aRepostedData = unserialize($aEvent['content']);
  1557. $sType = $aRepostedData['type'];
  1558. $sAction = $aRepostedData['action'];
  1559. $iObjectId = $aRepostedData['object_id'];
  1560. }
  1561. return $this->serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $bForce);
  1562. }
  1563. /**
  1564. * @page service Service Calls
  1565. * @section bx_timeline Timeline
  1566. * @subsection bx_timeline-other Other
  1567. * @subsubsection bx_timeline-update update
  1568. *
  1569. * @code bx_srv('bx_timeline', 'update', [...]); @endcode
  1570. *
  1571. * Update timeline event by ID.
  1572. *
  1573. * @param $iEventId integer value with event ID.
  1574. * @param $aSet an array with key=>value pairs for fields which should be updated.
  1575. * @return boolean value with the result of operation.
  1576. *
  1577. * @see BxTimelineModule::serviceUpdate
  1578. */
  1579. /**
  1580. * @ref bx_timeline-update "update"
  1581. */
  1582. public function serviceUpdate($iEventId, $aSet)
  1583. {
  1584. if(empty($iEventId))
  1585. return false;
  1586. return (int)$this->_oDb->updateEvent($aSet, array('id' => $iEventId)) > 0;
  1587. }
  1588. /**
  1589. * @page service Service Calls
  1590. * @section bx_timeline Timeline
  1591. * @subsection bx_timeline-other Other
  1592. * @subsubsection bx_timeline-get_menu_item_addon_comment get_menu_item_addon_comment
  1593. *
  1594. * @code bx_srv('bx_timeline', 'get_menu_item_addon_comment', [...]); @endcode
  1595. *
  1596. * Get addon for Comment menu item.
  1597. *
  1598. * @param $sSystem string value with comments engine system.
  1599. * @param $iObjectId integer value with object ID.
  1600. * @return HTML string to display in menu item.
  1601. *
  1602. * @see BxTimelineModule::serviceGetMenuItemAddonComment
  1603. */
  1604. /**
  1605. * @ref bx_timeline-get_menu_item_addon_comment "get_menu_item_addon_comment"
  1606. */
  1607. public function serviceGetMenuItemAddonComment($sSystem, $iObjectId, $aBrowseParams = array())
  1608. {
  1609. if(empty($sSystem) || empty($iObjectId))
  1610. return '';
  1611. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  1612. if($oCmts === false)
  1613. return '';
  1614. $iCounter = (int)$oCmts->getCommentsCount();
  1615. if(empty($iCounter))
  1616. return '';
  1617. return $this->_oTemplate->parseLink('javascript:void(0)', $iCounter, array(
  1618. 'class' => 'bx-menu-item-addon',
  1619. 'title' => _t('_bx_timeline_menu_item_title_item_comment'),
  1620. 'onclick' => "javascript:" . $this->_oConfig->getJsObjectView($aBrowseParams) . ".commentItem(this, '" . $sSystem . "', " . $iObjectId . ")"
  1621. ));
  1622. }
  1623. /**
  1624. * @page service Service Calls
  1625. * @section bx_timeline Timeline
  1626. * @subsection bx_timeline-other Other
  1627. * @subsubsection bx_timeline-get_settings_checker_helper get_settings_checker_helper
  1628. *
  1629. * @code bx_srv('bx_timeline', 'get_settings_checker_helper', [...]); @endcode
  1630. *
  1631. * Get Checker Helper class name for Forms engine.
  1632. *
  1633. * @return string with Checker Helper class name.
  1634. *
  1635. * @see BxTimelineModule::serviceGetSettingsCheckerHelper
  1636. */
  1637. /**
  1638. * @ref bx_timeline-get_settings_checker_helper "get_settings_checker_helper"
  1639. */
  1640. public function serviceGetSettingsCheckerHelper()
  1641. {
  1642. bx_import('FormCheckerHelper', $this->_aModule);
  1643. return 'BxTimelineFormCheckerHelper';
  1644. }
  1645. /**
  1646. * @page service Service Calls
  1647. * @section bx_timeline Timeline
  1648. * @subsection bx_timeline-other Other
  1649. * @subsubsection bx_timeline-get_options_videos_autoplay get_options_videos_autoplay
  1650. *
  1651. * @code bx_srv('bx_timeline', 'get_options_videos_autoplay', [...]); @endcode
  1652. *
  1653. * Get an array with available options for 'Videos autoplay in Timeline' setting.
  1654. *
  1655. * @return an array with available options represented as key => value pairs.
  1656. *
  1657. * @see BxTimelineModule::serviceGetOptionsVideosAutoplay
  1658. */
  1659. /**
  1660. * @ref bx_timeline-get_options_videos_autoplay "get_options_videos_autoplay"
  1661. */
  1662. public function serviceGetOptionsVideosAutoplay()
  1663. {
  1664. $aOptions = array(BX_TIMELINE_VAP_OFF, BX_TIMELINE_VAP_ON_MUTE, BX_TIMELINE_VAP_ON);
  1665. $aResult = array();
  1666. foreach($aOptions as $sOption)
  1667. $aResult[] = array(
  1668. 'key' => $sOption,
  1669. 'value' => _t('_bx_timeline_option_videos_autoplay_' . $sOption)
  1670. );
  1671. return $aResult;
  1672. }
  1673. /**
  1674. * @page service Service Calls
  1675. * @section bx_timeline Timeline
  1676. * @subsection bx_timeline-other Other
  1677. * @subsubsection bx_timeline-get_live_updates get_live_updates
  1678. *
  1679. * @code bx_srv('bx_timeline', 'get_live_updates', [...]); @endcode
  1680. *
  1681. * Get an array with actual Live Update info.
  1682. *
  1683. * @return an array with Live Update info.
  1684. *
  1685. * @see BxTimelineModule::serviceGetLiveUpdates
  1686. */
  1687. /**
  1688. * @ref bx_timeline-get_live_updates "get_live_updates"
  1689. */
  1690. public function serviceGetLiveUpdates($aBrowseParams, $iProfileId, $iCount = 0, $iInit = 0)
  1691. {
  1692. $sKey = $this->_oConfig->getLiveUpdateKey($aBrowseParams);
  1693. bx_import('BxDolSession');
  1694. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  1695. return false;
  1696. $aParams = $this->_prepareParams($aBrowseParams);
  1697. $aParams['filter'] = BX_TIMELINE_FILTER_OTHER_VIEWER;
  1698. $aParams['count'] = true;
  1699. $iCountNew = $this->_oDb->getEvents($aParams);
  1700. if($iCountNew == $iCount)
  1701. return false;
  1702. if((int)$iInit != 0)
  1703. return array('count' => $iCountNew);
  1704. return array(
  1705. 'count' => $iCountNew, // required (for initialization and visualization)
  1706. 'method' => $this->_oConfig->getJsObjectView($aBrowseParams) . '.showLiveUpdate(oData)', // required (for visualization)
  1707. 'data' => array(
  1708. 'code' => $this->_oTemplate->getLiveUpdateNotification($aBrowseParams, $iProfileId, $iCount, $iCountNew)
  1709. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  1710. );
  1711. }
  1712. /**
  1713. * @page service Service Calls
  1714. * @section bx_timeline Accounts
  1715. * @subsection bx_timeline-other Other
  1716. * @subsubsection bx_timeline-get_menu_addon_manage_tools get_menu_addon_manage_tools
  1717. *
  1718. * @code bx_srv('bx_timeline', 'get_menu_addon_manage_tools', [...]); @endcode
  1719. *
  1720. * Get number of 'hidden' events for User End -> Dasboard page -> Manage block.
  1721. *
  1722. * @return integer number of 'hidden' events
  1723. *
  1724. * @see BxTimelineModule::serviceGetMenuAddonManageTools
  1725. */
  1726. /**
  1727. * @ref bx_timeline-get_menu_addon_manage_tools "get_menu_addon_manage_tools"
  1728. */
  1729. public function serviceGetMenuAddonManageTools()
  1730. {
  1731. bx_import('SearchResult', $this->_aModule);
  1732. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  1733. $o = new $sClass();
  1734. $o->fillFilters(array(
  1735. 'active' => 0
  1736. ));
  1737. $o->unsetPaginate();
  1738. return $o->getNum();
  1739. }
  1740. /*
  1741. * COMMON METHODS
  1742. */
  1743. public function deleteEvent($aEvent)
  1744. {
  1745. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->deleteEvent(array('id' => (int)$aEvent['id'])))
  1746. return false;
  1747. $this->onDelete($aEvent);
  1748. return true;
  1749. }
  1750. public function addAttachLink($aValues, $sDisplay = false)
  1751. {
  1752. $CNF = &$this->_oConfig->CNF;
  1753. if(!$sDisplay)
  1754. $sDisplay = $this->_oConfig->getObject('form_display_attach_link_add');
  1755. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $sDisplay, $this->_oTemplate);
  1756. if(!$oForm)
  1757. return array('message' => '_sys_txt_error_occured');
  1758. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  1759. $oForm->aParams['csrf']['disable'] = true;
  1760. if(!empty($oForm->aParams['db']['submit_name'])) {
  1761. $sSubmitName = $oForm->aParams['db']['submit_name'];
  1762. if(!isset($oForm->aInputs[$sSubmitName])) {
  1763. if(isset($oForm->aInputs[$CNF['FIELD_CONTROLS']]))
  1764. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  1765. if(!is_numeric($mixedIndex) || empty($aInput['name']) || $aInput['name'] != $sSubmitName)
  1766. continue;
  1767. $aValues[$sSubmitName] = $aInput['value'];
  1768. }
  1769. }
  1770. else
  1771. $aValues[$sSubmitName] = $oForm->aInputs[$sSubmitName]['value'];
  1772. }
  1773. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  1774. $oForm->initChecker(array(), $aValues);
  1775. if(!$oForm->isSubmittedAndValid())
  1776. return array('message' => '_sys_txt_error_occured');
  1777. return $this->_addLink($oForm);
  1778. }
  1779. public function getFormAttachLink()
  1780. {
  1781. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $this->_oConfig->getObject('form_display_attach_link_add'), $this->_oTemplate);
  1782. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_attach_link_form/';
  1783. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  1784. $oForm->initChecker();
  1785. if($oForm->isSubmittedAndValid())
  1786. return $this->_addLink($oForm);
  1787. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  1788. }
  1789. public function getFormPost($aParams = array())
  1790. {
  1791. $iUserId = $this->getUserId();
  1792. $oForm = $this->getFormPostObject($aParams);
  1793. $oForm->initChecker();
  1794. $bAjaxMode = $oForm->isAjaxMode();
  1795. $bDynamicMode = $bAjaxMode;
  1796. if($oForm->isSubmittedAndValid()) {
  1797. list($sUserName) = $this->getUserInfo($iUserId);
  1798. $sType = $oForm->getCleanValue('type');
  1799. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  1800. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  1801. $aContent = array();
  1802. //--- Process Text ---//
  1803. $sText = $oForm->getCleanValue('text');
  1804. $sText = $this->_prepareTextForSave($sText);
  1805. $bText = !empty($sText);
  1806. if($bText)
  1807. $aContent['text'] = $sText;
  1808. //--- Process Context and Privacy ---//
  1809. $iOwnerId = (int)$oForm->getCleanValue('owner_id');
  1810. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  1811. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  1812. if(empty($iObjectPrivacyView))
  1813. $iObjectPrivacyView = $iObjectPrivacyViewDefault;
  1814. else if($iObjectPrivacyView < 0)
  1815. $iOwnerId = abs($iObjectPrivacyView);
  1816. //--- Process Link ---//
  1817. $aLinkIds = $oForm->getCleanValue('link');
  1818. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  1819. //--- Process Media ---//
  1820. $aPhotoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_PHOTO);
  1821. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  1822. $aVideoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_VIDEO);
  1823. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  1824. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds) {
  1825. $oForm->aInputs['text']['error'] = _t('_bx_timeline_txt_err_empty_post');
  1826. $oForm->setValid(false);
  1827. return $this->_prepareResponse(array('form' => $oForm->getCode($bDynamicMode), 'form_id' => $oForm->id), $bAjaxMode);
  1828. }
  1829. $sTitle = $bText ? $this->_oConfig->getTitle($sText) : $this->_oConfig->getTitleDefault($bLinkIds, $bPhotoIds, $bVideoIds);
  1830. $sDescription = _t('_bx_timeline_txt_user_added_sample', '{profile_name}', _t('_bx_timeline_txt_sample_with_article'));
  1831. //--- Process Date ---//
  1832. $iDate = 0;
  1833. if(isset($oForm->aInputs['date']))
  1834. $iDate = $oForm->getCleanValue('date');
  1835. if(empty($iDate))
  1836. $iDate = time();
  1837. /**
  1838. * Unset 'text' input because its data was already processed
  1839. * and will be saved via additional values which were passed
  1840. * to BxDolForm::insert method.
  1841. */
  1842. unset($oForm->aInputs['text']);
  1843. $iId = $oForm->insert(array(
  1844. 'owner_id' => $iOwnerId,
  1845. 'object_id' => $iUserId,
  1846. 'object_privacy_view' => $iObjectPrivacyView,
  1847. 'content' => serialize($aContent),
  1848. 'title' => $sTitle,
  1849. 'description' => $sDescription,
  1850. 'date' => $iDate
  1851. ));
  1852. if(!empty($iId)) {
  1853. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  1854. if($bText)
  1855. $oMetatags->metaAdd($iId, $sText);
  1856. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  1857. //--- Process Link ---//
  1858. if($bLinkIds)
  1859. foreach($aLinkIds as $iLinkId)
  1860. $this->_oDb->saveLink($iId, $iLinkId);
  1861. //--- Process Media ---//
  1862. if($bPhotoIds)
  1863. $this->_saveMedia(BX_TIMELINE_MEDIA_PHOTO, $iId, $aPhotoIds);
  1864. if($bVideoIds)
  1865. $this->_saveMedia(BX_TIMELINE_MEDIA_VIDEO, $iId, $aVideoIds);
  1866. $this->onPost($iId);
  1867. return $this->_prepareResponse(array('id' => $iId), $bAjaxMode, array(
  1868. 'redirect' => $this->_oConfig->getItemViewUrl(array('id' => $iId))
  1869. ));
  1870. }
  1871. return $this->_prepareResponse(array('message' => _t('_bx_timeline_txt_err_cannot_perform_action')), $bAjaxMode);
  1872. }
  1873. return $this->_prepareResponse(array('form' => $oForm->getCode($bDynamicMode), 'form_id' => $oForm->id), $bAjaxMode && $oForm->isSubmitted());
  1874. }
  1875. public function getFormEdit($iId, $aParams = array(), $aBrowseParams = array())
  1876. {
  1877. $CNF = &$this->_oConfig->CNF;
  1878. $sJsObjectView = $this->_oConfig->getJsObjectView($aBrowseParams);
  1879. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  1880. if(empty($aEvent) || !is_array($aEvent))
  1881. return array();
  1882. $aContent = unserialize($aEvent['content']);
  1883. if(is_array($aContent) && !empty($aContent['text']))
  1884. $aEvent['text'] = $aContent['text'];
  1885. $bDynamicMode = isset($aParams['dynamic_mode']) ? (bool)$aParams['dynamic_mode'] : false;
  1886. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  1887. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_edit';
  1888. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  1889. $oForm->setId($this->_oConfig->getHtmlIds('view', 'edit_form') . $iId);
  1890. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'edit/' . $iId ;
  1891. if(!empty($aBrowseParams) && is_array($aBrowseParams))
  1892. $oForm->aFormAttrs['action'] = $this->_oConfig->addBrowseParams($oForm->aFormAttrs['action'], $aBrowseParams);
  1893. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  1894. if(!is_numeric($mixedIndex))
  1895. continue;
  1896. $oForm->aInputs[$CNF['FIELD_CONTROLS']][$mixedIndex]['attrs'] = bx_replace_markers($aInput['attrs'], array(
  1897. 'js_object_view' => $sJsObjectView,
  1898. 'content_id' => $iId
  1899. ));
  1900. }
  1901. $oForm->initChecker($aEvent);
  1902. if($oForm->isSubmittedAndValid()) {
  1903. $aContent = array();
  1904. //--- Process Text ---//
  1905. $sText = $oForm->getCleanValue('text');
  1906. $sText = $this->_prepareTextForSave($sText);
  1907. $bText = !empty($sText);
  1908. unset($oForm->aInputs['text']);
  1909. if($bText)
  1910. $aContent['text'] = $sText;
  1911. $aValsToAdd = array(
  1912. 'content' => serialize($aContent)
  1913. );
  1914. //--- Process Privacy ---//
  1915. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  1916. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  1917. if(empty($iObjectPrivacyView))
  1918. $aValsToAdd = array_merge($aValsToAdd, array(
  1919. 'object_privacy_view' => $iObjectPrivacyViewDefault
  1920. ));
  1921. else if($iObjectPrivacyView < 0)
  1922. $aValsToAdd = array_merge($aValsToAdd, array(
  1923. 'owner_id' => abs($iObjectPrivacyView),
  1924. 'object_privacy_view' => $iObjectPrivacyViewDefault
  1925. ));
  1926. //--- Process Date ---//
  1927. if(isset($oForm->aInputs['date'])) {
  1928. $iDate = $oForm->getCleanValue('date');
  1929. if(empty($iDate))
  1930. $iDate = time();
  1931. $aValsToAdd['date'] = $iDate;
  1932. }
  1933. if(!$oForm->update($iId, $aValsToAdd))
  1934. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  1935. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  1936. if($bText)
  1937. $oMetatags->metaAdd($iId, $sText);
  1938. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  1939. return array(
  1940. 'id' => $iId
  1941. );
  1942. }
  1943. return array(
  1944. 'id' => $iId,
  1945. 'form' => $oForm->getCode($bDynamicMode),
  1946. 'form_id' => $oForm->id,
  1947. 'eval' => $sJsObjectView . '.onEditPost(oData)'
  1948. );
  1949. }
  1950. public function getFormPostObject($aParams)
  1951. {
  1952. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  1953. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_add';
  1954. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  1955. $sParamsKey = 'ajax_mode';
  1956. if(isset($aParams[$sParamsKey]) && is_bool($aParams[$sParamsKey]))
  1957. $oForm->setAjaxMode((bool)$aParams[$sParamsKey]);
  1958. $sParamsKey = 'visibility_autoselect';
  1959. if(isset($aParams[$sParamsKey]) && is_bool($aParams[$sParamsKey]))
  1960. $oForm->setVisibilityAutoselect((bool)$aParams[$sParamsKey]);
  1961. $oForm->init();
  1962. return $oForm;
  1963. }
  1964. public function getCmtsObject($sSystem, $iId)
  1965. {
  1966. if(empty($sSystem) || (int)$iId == 0)
  1967. return false;
  1968. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1969. if(!$oCmts || !$oCmts->isEnabled())
  1970. return false;
  1971. return $oCmts;
  1972. }
  1973. public function getViewObject($sSystem, $iId)
  1974. {
  1975. if(empty($sSystem) || (int)$iId == 0)
  1976. return false;
  1977. $oView = BxDolView::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1978. if(!$oView || !$oView->isEnabled())
  1979. return false;
  1980. return $oView;
  1981. }
  1982. public function getVoteObject($sSystem, $iId)
  1983. {
  1984. if(empty($sSystem) || (int)$iId == 0)
  1985. return false;
  1986. $oVote = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1987. if(!$oVote || !$oVote->isEnabled())
  1988. return false;
  1989. return $oVote;
  1990. }
  1991. public function getScoreObject($sSystem, $iId)
  1992. {
  1993. if(empty($sSystem) || (int)$iId == 0)
  1994. return false;
  1995. $oScore = BxDolScore::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1996. if(!$oScore || !$oScore->isEnabled())
  1997. return false;
  1998. return $oScore;
  1999. }
  2000. public function getReportObject($sSystem, $iId)
  2001. {
  2002. if(empty($sSystem) || (int)$iId == 0)
  2003. return false;
  2004. $oReport = BxDolReport::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2005. if(!$oReport || !$oReport->isEnabled())
  2006. return false;
  2007. return $oReport;
  2008. }
  2009. public function getAttachmentsMenuObject()
  2010. {
  2011. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post_attachments'), $this->_oTemplate);
  2012. $oMenu->addMarkers(array(
  2013. 'js_object' => $this->_oConfig->getJsObject('post'),
  2014. ));
  2015. return $oMenu;
  2016. }
  2017. public function getManageMenuObject()
  2018. {
  2019. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'), $this->_oTemplate);
  2020. }
  2021. //--- Check permissions methods ---//
  2022. public function isModerator()
  2023. {
  2024. $sModule = $this->getName();
  2025. $iUserId = (int)$this->getUserId();
  2026. $aCheckResult = checkActionModule($iUserId, 'edit', $sModule);
  2027. if($aCheckResult[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2028. return true;
  2029. $aCheckResult = checkActionModule($iUserId, 'delete', $sModule);
  2030. if($aCheckResult[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2031. return true;
  2032. return false;
  2033. }
  2034. public function isAllowedPost($bPerform = false)
  2035. {
  2036. if(isAdmin())
  2037. return true;
  2038. $iUserId = $this->getUserId();
  2039. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  2040. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  2041. if($oProfileOwner !== false) {
  2042. if($oProfileOwner->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  2043. return _t('_sys_txt_access_denied');
  2044. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_post', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2045. }
  2046. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2047. }
  2048. public function isAllowedView($aEvent, $bPerform = false)
  2049. {
  2050. $CNF = $this->_oConfig->CNF;
  2051. $mixedResult = BxDolProfile::getInstance($aEvent[$CNF['FIELD_OWNER_ID']])->checkAllowedProfileView();
  2052. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  2053. return false;
  2054. return true;
  2055. }
  2056. public function isAllowedEdit($aEvent, $bPerform = false)
  2057. {
  2058. if(!isLogged())
  2059. return false;
  2060. //--- System posts and Reposts cannot be edited at all.
  2061. if(!$this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) || $aEvent['type'] == $this->_oConfig->getPrefix('common_post') . 'repost')
  2062. return false;
  2063. if(isAdmin())
  2064. return true;
  2065. $iUserId = (int)$this->getUserId();
  2066. $iOwnerId = (int)$aEvent['owner_id'];
  2067. $iObjectId = abs((int)$aEvent['object_id']);
  2068. if($iObjectId == $iUserId && $this->_oConfig->isAllowEdit())
  2069. return true;
  2070. $aCheckResult = checkActionModule($iUserId, 'edit', $this->getName(), $bPerform);
  2071. $oProfileOwner = BxDolProfile::getInstance($iOwnerId);
  2072. if($oProfileOwner !== false)
  2073. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_edit', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2074. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2075. }
  2076. public function isAllowedDelete($aEvent, $bPerform = false)
  2077. {
  2078. if(!isLogged())
  2079. return false;
  2080. if(isAdmin())
  2081. return true;
  2082. $iUserId = (int)$this->getUserId();
  2083. $iOwnerId = (int)$aEvent['owner_id'];
  2084. $iObjectId = abs((int)$aEvent['object_id']);
  2085. if((($iOwnerId == $iUserId && $this->_oConfig->isAllowDelete()) || ($this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && $iObjectId == $iUserId)))
  2086. return true;
  2087. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  2088. $oProfileOwner = BxDolProfile::getInstance($iOwnerId);
  2089. if($oProfileOwner !== false)
  2090. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_delete', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2091. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2092. }
  2093. public function isAllowedComment($aEvent, $bPerform = false)
  2094. {
  2095. $mixedComments = $this->getCommentsData($aEvent['comments']);
  2096. if($mixedComments === false)
  2097. return false;
  2098. list($sSystem, $iObjectId) = $mixedComments;
  2099. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  2100. $oCmts->addCssJs();
  2101. $bResult = true;
  2102. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  2103. if($oProfileOwner !== false) {
  2104. if($oProfileOwner->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  2105. return false;
  2106. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_comment', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2107. }
  2108. return $bResult;
  2109. }
  2110. public function isAllowedViewCounter($aEvent, $bPerform = false)
  2111. {
  2112. $mixedViews = $this->getViewsData($aEvent['views']);
  2113. if($mixedViews === false)
  2114. return false;
  2115. list($sSystem, $iObjectId) = $mixedViews;
  2116. $oView = $this->getViewObject($sSystem, $iObjectId);
  2117. if(!$oView->isAllowedViewView($bPerform))
  2118. return false;
  2119. $bResult = true;
  2120. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  2121. if($oProfileOwner !== false)
  2122. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view_counter', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2123. return $bResult;
  2124. }
  2125. public function isAllowedVote($aEvent, $bPerform = false)
  2126. {
  2127. $mixedVotes = $this->getVotesData($aEvent['votes']);
  2128. if($mixedVotes === false)
  2129. return false;
  2130. list($sSystem, $iObjectId) = $mixedVotes;
  2131. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  2132. if(!$oVote->isAllowedVote($bPerform))
  2133. return false;
  2134. $bResult = true;
  2135. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  2136. if($oProfileOwner !== false)
  2137. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2138. return $bResult;
  2139. }
  2140. public function isAllowedScore($aEvent, $bPerform = false)
  2141. {
  2142. $mixedScores = $this->getScoresData($aEvent['scores']);
  2143. if($mixedScores === false)
  2144. return false;
  2145. list($sSystem, $iObjectId) = $mixedScores;
  2146. $oScore = $this->getScoreObject($sSystem, $iObjectId);
  2147. if(!$oScore->isAllowedVote($bPerform))
  2148. return false;
  2149. $bResult = true;
  2150. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  2151. if($oProfileOwner !== false)
  2152. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_score', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2153. return $bResult;
  2154. }
  2155. public function isAllowedReport($aEvent, $bPerform = false)
  2156. {
  2157. $mixedReports = $this->getReportsData($aEvent['reports']);
  2158. if($mixedReports === false)
  2159. return false;
  2160. list($sSystem, $iObjectId) = $mixedReports;
  2161. $oReport = $this->getReportObject($sSystem, $iObjectId);
  2162. if(!$oReport->isAllowedReport($bPerform))
  2163. return false;
  2164. $bResult = true;
  2165. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  2166. if($oProfileOwner !== false)
  2167. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_report', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2168. return $bResult;
  2169. }
  2170. public function isAllowedRepost($aEvent, $bPerform = false)
  2171. {
  2172. $iUserId = (int)$this->getUserId();
  2173. if($iUserId == 0)
  2174. return false;
  2175. $iPrivacy = $this->getObjectPrivacyView(is_array($aEvent['content']) ? $aEvent['content'] : unserialize($aEvent['content']));
  2176. if(!in_array($iPrivacy, array(BX_DOL_PG_ALL, BX_DOL_PG_MEMBERS)))
  2177. return false;
  2178. if(isAdmin())
  2179. return true;
  2180. $aCheckResult = checkActionModule($iUserId, 'repost', $this->getName(), $bPerform);
  2181. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  2182. if($oProfileOwner !== false)
  2183. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_repost', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2184. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2185. }
  2186. public function isAllowedSend($aEvent, $bPerform = false)
  2187. {
  2188. if(!$this->_oDb->isEnabledByName('bx_convos'))
  2189. return false;
  2190. if(isAdmin())
  2191. return true;
  2192. $iUserId = (int)$this->getUserId();
  2193. if($iUserId == 0)
  2194. return false;
  2195. $aCheckResult = checkActionModule($iUserId, 'send', $this->getName(), $bPerform);
  2196. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  2197. if($oProfileOwner !== false)
  2198. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_send', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2199. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2200. }
  2201. /**
  2202. * Pin - "Pin here" - pin the post on Profile Timeline for profile owner.
  2203. * Can be done by profile owner for himself or by admin for profile owner to see.
  2204. * @param type $aEvent
  2205. * @param type $bPerform
  2206. * @return boolean
  2207. */
  2208. public function isAllowedPin($aEvent, $bPerform = false)
  2209. {
  2210. if((int)$aEvent['pinned'] != 0)
  2211. return false;
  2212. return $this->_isAllowedPin($aEvent, $bPerform);
  2213. }
  2214. public function isAllowedUnpin($aEvent, $bPerform = false)
  2215. {
  2216. if((int)$aEvent['pinned'] == 0)
  2217. return false;
  2218. return $this->_isAllowedPin($aEvent, $bPerform);
  2219. }
  2220. /**
  2221. * Stick - "Pin for All" - pin the post on Public Timeline for everybody to see.
  2222. * Is available for Administrators/Moderators only.
  2223. * @param type $aEvent
  2224. * @param type $bPerform
  2225. * @return boolean
  2226. */
  2227. public function isAllowedStick($aEvent, $bPerform = false)
  2228. {
  2229. if((int)$aEvent['sticked'] != 0)
  2230. return false;
  2231. return $this->_isAllowedStick($aEvent, $bPerform);
  2232. }
  2233. public function isAllowedUnstick($aEvent, $bPerform = false)
  2234. {
  2235. if((int)$aEvent['sticked'] == 0)
  2236. return false;
  2237. return $this->_isAllowedStick($aEvent, $bPerform);
  2238. }
  2239. public function isAllowedPromote($aEvent, $bPerform = false)
  2240. {
  2241. if((int)$aEvent['promoted'] != 0)
  2242. return false;
  2243. return $this->_isAllowedPromote($aEvent, $bPerform);
  2244. }
  2245. public function isAllowedUnpromote($aEvent, $bPerform = false)
  2246. {
  2247. if((int)$aEvent['promoted'] == 0)
  2248. return false;
  2249. return $this->_isAllowedPromote($aEvent, $bPerform);
  2250. }
  2251. public function isAllowedMore($aEvent, $bPerform = false)
  2252. {
  2253. $oMoreMenu = $this->getManageMenuObject();
  2254. $oMoreMenu->setEventById($aEvent['id']);
  2255. return $oMoreMenu->isVisible();
  2256. }
  2257. public function checkAllowedView ($aContentInfo, $isPerformAction = false)
  2258. {
  2259. if(!$this->isAllowedView($aContentInfo, $isPerformAction))
  2260. return _t('_sys_txt_access_denied');
  2261. return CHECK_ACTION_RESULT_ALLOWED;
  2262. }
  2263. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  2264. {
  2265. $CNF = $this->_oConfig->CNF;
  2266. $iOwner = (int)$aContentInfo[$CNF['FIELD_OWNER_ID']];
  2267. if($iOwner == 0) //--- in case of Public Timeline.
  2268. return CHECK_ACTION_RESULT_ALLOWED;
  2269. $oOwner = BxDolProfile::getInstance($iOwner);
  2270. if(!$oOwner) //--- in case of non-existed Timeline owner.
  2271. return _t('_sys_txt_access_denied');
  2272. $mixedResult = $oOwner->checkAllowedProfileView();
  2273. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  2274. return $mixedResult;
  2275. return CHECK_ACTION_RESULT_ALLOWED;
  2276. }
  2277. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  2278. {
  2279. $sError = '_sys_txt_access_denied';
  2280. $aContentInfo = $this->_oTemplate->getData($aContentInfo);
  2281. if($aContentInfo === false)
  2282. return _t($sError);
  2283. if(!$this->isAllowedComment($aContentInfo, $isPerformAction))
  2284. return _t($sError);
  2285. return CHECK_ACTION_RESULT_ALLOWED;
  2286. }
  2287. public function onPost($iId)
  2288. {
  2289. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  2290. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  2291. //--- Request event's data from content module and update it in the Timeline DB.
  2292. $this->_oTemplate->getData($aEvent);
  2293. $sPostType = 'system';
  2294. $iSenderId = $iObjectAuthorId = (int)$aEvent['owner_id'];
  2295. }
  2296. else {
  2297. $sPostType = 'common';
  2298. $iSenderId = $iObjectAuthorId = (int)$aEvent['object_id'];
  2299. }
  2300. //--- Event -> Post for Alerts Engine ---//
  2301. bx_alert($this->_oConfig->getObject('alert'), 'post_' . $sPostType, $iId, $iSenderId, array(
  2302. 'owner_id' => $aEvent['owner_id'],
  2303. 'object_author_id' => $iObjectAuthorId,
  2304. 'privacy_view' => $aEvent['object_privacy_view'],
  2305. ));
  2306. //--- Event -> Post for Alerts Engine ---//
  2307. }
  2308. public function onRepost($iId, $aReposted = array())
  2309. {
  2310. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  2311. if(empty($aReposted)) {
  2312. $aContent = unserialize($aEvent['content']);
  2313. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  2314. if(empty($aReposted) || !is_array($aReposted))
  2315. return;
  2316. }
  2317. $iUserId = $this->getUserId();
  2318. $this->_oDb->insertRepostTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aReposted['id']);
  2319. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts']);
  2320. //--- Timeline -> Update for Alerts Engine ---//
  2321. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'repost', $aReposted['id'], $iUserId, array(
  2322. 'privacy_view' => $aEvent['object_privacy_view'],
  2323. 'object_author_id' => $aReposted['owner_id'],
  2324. 'repost_id' => $iId,
  2325. ));
  2326. $oAlert->alert();
  2327. //--- Timeline -> Update for Alerts Engine ---//
  2328. }
  2329. public function onDelete($aEvent)
  2330. {
  2331. $iUserId = $this->getUserId();
  2332. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  2333. $sCommonPostComment = $this->_oConfig->getObject('comment');
  2334. //--- Delete comments for Common posts.
  2335. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  2336. $oComments = $this->getCmtsObject($sCommonPostComment, $aEvent['id']);
  2337. if($oComments !== false)
  2338. $oComments->onObjectDelete($aEvent['id']);
  2339. }
  2340. //--- Delete attached photos, videos and links when common event was deleted.
  2341. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  2342. $this->_deleteMedia(BX_TIMELINE_MEDIA_PHOTO, $aEvent['id']);
  2343. $this->_deleteMedia(BX_TIMELINE_MEDIA_VIDEO, $aEvent['id']);
  2344. $this->_deleteLinks($aEvent['id']);
  2345. }
  2346. //--- Update parent event when repost event was deleted.
  2347. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  2348. if($bRepost) {
  2349. $this->_oDb->deleteRepostTrack($aEvent['id']);
  2350. $aContent = unserialize($aEvent['content']);
  2351. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  2352. if(!empty($aReposted) && is_array($aReposted))
  2353. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts'], -1);
  2354. }
  2355. //--- Find and delete repost events when parent event was deleted.
  2356. $bSystem = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']);
  2357. $aRepostEvents = $this->_oDb->getEvents(array('browse' => 'reposted_by_descriptor', 'type' => $aEvent['type']));
  2358. foreach($aRepostEvents as $aRepostEvent) {
  2359. $aContent = unserialize($aRepostEvent['content']);
  2360. 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) {
  2361. $oComments = $this->getCmtsObject($sCommonPostComment, $aRepostEvent['id']);
  2362. if($oComments !== false)
  2363. $oComments->onObjectDelete($aRepostEvent['id']);
  2364. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aEvent['id'], $iUserId, array(
  2365. 'repost_id' => $aRepostEvent['id'],
  2366. ));
  2367. }
  2368. }
  2369. //--- Delete associated meta.
  2370. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  2371. $oMetatags->onDeleteContent($aEvent['id']);
  2372. //--- Event -> Delete for Alerts Engine ---//
  2373. if($bRepost)
  2374. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aReposted['id'], $iUserId, array(
  2375. 'repost_id' => $aEvent['id'],
  2376. ));
  2377. else
  2378. bx_alert($this->_oConfig->getObject('alert'), 'delete', $aEvent['id'], $iUserId);
  2379. //--- Event -> Delete for Alerts Engine ---//
  2380. }
  2381. public function getParams($sView = '', $sType = '', $iOwnerId = 0, $iStart = 0, $iPerPage = 0, $sFilter = BX_TIMELINE_FILTER_ALL, $aModules = array(), $iTimeline = 0)
  2382. {
  2383. return $this->_prepareParams(array(
  2384. 'view' => $sView,
  2385. 'type' => $sType,
  2386. 'owner_id' => $iOwnerId,
  2387. 'start' => $iStart,
  2388. 'per_page' => $iPerPage,
  2389. 'timeline' => $iTimeline,
  2390. 'filter' => $sFilter,
  2391. 'modules' => $aModules
  2392. ));
  2393. }
  2394. public function getParamsExt($aParams = array())
  2395. {
  2396. return $this->_prepareParams($aParams);
  2397. }
  2398. public function getViewsData(&$aViews)
  2399. {
  2400. if(empty($aViews) || !is_array($aViews))
  2401. return false;
  2402. $sSystem = isset($aViews['system']) ? $aViews['system'] : '';
  2403. $iObjectId = isset($aViews['object_id']) ? (int)$aViews['object_id'] : 0;
  2404. $iCount = isset($aViews['count']) ? (int)$aViews['count'] : 0;
  2405. if($sSystem == '' || $iObjectId == 0)
  2406. return false;
  2407. return array($sSystem, $iObjectId, $iCount);
  2408. }
  2409. public function getVotesData(&$aVotes)
  2410. {
  2411. if(empty($aVotes) || !is_array($aVotes))
  2412. return false;
  2413. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  2414. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  2415. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  2416. if($sSystem == '' || $iObjectId == 0)
  2417. return false;
  2418. return array($sSystem, $iObjectId, $iCount);
  2419. }
  2420. public function getScoresData(&$aScores)
  2421. {
  2422. if(empty($aScores) || !is_array($aScores))
  2423. return false;
  2424. $sSystem = isset($aScores['system']) ? $aScores['system'] : '';
  2425. $iObjectId = isset($aScores['object_id']) ? (int)$aScores['object_id'] : 0;
  2426. $iScore = isset($aScores['score']) ? (int)$aScores['score'] : 0;
  2427. if($sSystem == '' || $iObjectId == 0)
  2428. return false;
  2429. return array($sSystem, $iObjectId, $iScore);
  2430. }
  2431. public function getReportsData(&$aReports)
  2432. {
  2433. if(empty($aReports) || !is_array($aReports))
  2434. return false;
  2435. $sSystem = isset($aReports['system']) ? $aReports['system'] : '';
  2436. $iObjectId = isset($aReports['object_id']) ? (int)$aReports['object_id'] : 0;
  2437. $iCount = isset($aReports['count']) ? (int)$aReports['count'] : 0;
  2438. if($sSystem == '' || $iObjectId == 0)
  2439. return false;
  2440. return array($sSystem, $iObjectId, $iCount);
  2441. }
  2442. public function getCommentsData(&$aComments)
  2443. {
  2444. if(empty($aComments) || !is_array($aComments))
  2445. return false;
  2446. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  2447. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  2448. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  2449. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  2450. return false;
  2451. return array($sSystem, $iObjectId, $iCount);
  2452. }
  2453. public function getUserInfo($iUserId = 0)
  2454. {
  2455. $iLoggedId = $this->getUserId();
  2456. $iUserId = (int)$iUserId;
  2457. return parent::getUserInfo($iUserId);
  2458. }
  2459. /**
  2460. * Protected Methods
  2461. */
  2462. protected function _serviceGetBlockView($iProfileId = 0, $aBrowseParams = array())
  2463. {
  2464. if(empty($iProfileId) && bx_get('profile_id') !== false)
  2465. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  2466. if(empty($iProfileId) && isLogged())
  2467. $iProfileId = bx_get_logged_profile_id();
  2468. $aBrowseParams['owner_id'] = $iProfileId;
  2469. $aBlock = $this->_getBlockView($aBrowseParams);
  2470. if(!empty($aBlock))
  2471. return $aBlock;
  2472. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  2473. }
  2474. protected function _serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $aBrowseParams = array())
  2475. {
  2476. if(empty($sProfileModule))
  2477. return array();
  2478. if(empty($iProfileContentId) && bx_get('id') !== false)
  2479. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2480. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  2481. if(empty($oProfile))
  2482. return array();
  2483. $aBrowseParams['owner_id'] = $oProfile->id();
  2484. return $this->_getBlockView($aBrowseParams);
  2485. }
  2486. protected function _serviceGetBlockViewHome($aBrowseParams = array())
  2487. {
  2488. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  2489. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_home'), $sRssUrl);
  2490. return $this->_serviceGetBlockViewByType($aBrowseParams);
  2491. }
  2492. protected function _serviceGetBlockViewHot($aBrowseParams = array())
  2493. {
  2494. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  2495. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_hot'), $sRssUrl);
  2496. return $this->_serviceGetBlockViewByType($aBrowseParams);
  2497. }
  2498. protected function _serviceGetBlockViewByType($aBrowseParams = array())
  2499. {
  2500. $aParams = $this->_prepareParams($aBrowseParams);
  2501. if(isset($aParams['per_page']) && (int)$aParams['per_page'] <= 0)
  2502. $aParams['per_page'] = isset($aBrowseParams['per_page_default']) && (int)$aBrowseParams['per_page_default'] > 0 ? $aBrowseParams['per_page_default'] : $this->_oConfig->getPerPage();
  2503. $this->_iOwnerId = $aParams['owner_id'];
  2504. return array(
  2505. 'content' => $this->_oTemplate->getViewBlock($aParams)
  2506. );
  2507. }
  2508. protected function _getBlockPost($iProfileId, $aParams = array())
  2509. {
  2510. $this->_iOwnerId = $iProfileId;
  2511. if($this->isAllowedPost() !== true)
  2512. return array();
  2513. return array(
  2514. 'content' => $this->_oTemplate->getPostBlock($this->_iOwnerId, $aParams)
  2515. );
  2516. }
  2517. protected function _getBlockView($aBrowseParams = array())
  2518. {
  2519. if(empty($aBrowseParams['owner_id']))
  2520. return array();
  2521. $aParams = $this->_prepareParams($aBrowseParams);
  2522. if(empty($aParams['per_page']))
  2523. $aParams['per_page'] = $this->_oConfig->getPerPage('profile');
  2524. $this->_iOwnerId = $aParams['owner_id'];
  2525. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  2526. $mixedResult = $oProfileOwner->checkAllowedProfileView();
  2527. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  2528. return array('content' => MsgBox($mixedResult));
  2529. list($sUserName) = $this->getUserInfo($aParams['owner_id']);
  2530. $sView = $aParams['view'];
  2531. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_OWNER . '/' . $this->_iOwnerId . '/';
  2532. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  2533. $aMenu = array(
  2534. 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),
  2535. 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)),
  2536. 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')),
  2537. array('id' => $sView . '-get-rss', 'name' => $sView . '-get-rss', 'class' => '', 'link' => $sRssUrl, 'onclick' => '', 'target' => '_blank', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  2538. );
  2539. $sContent = '';
  2540. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view', $this->_iOwnerId, $this->getUserId(), array('override_content' => &$sContent, 'params' => &$aParams, 'menu' => &$aMenu));
  2541. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $sView . '-view-all', 'menu_items' => $aMenu));
  2542. $oMenu->setSelected('', $sView . '-view-all');
  2543. if (!$sContent)
  2544. $sContent = $this->_oTemplate->getViewBlock($aParams);
  2545. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view'), $sRssUrl);
  2546. return array('content' => $sContent, 'menu' => $oMenu);
  2547. }
  2548. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  2549. {
  2550. $CNF = &$this->_oConfig->CNF;
  2551. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  2552. $sText = '';
  2553. if(isset($aContentInfo['content'])){
  2554. $aTmp = unserialize($aContentInfo['content']);
  2555. if(isset($aTmp['text']))
  2556. $sText = $aTmp['text'];
  2557. }
  2558. if(empty($sText) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  2559. $sText = $aContentInfo[$CNF['FIELD_TITLE']];
  2560. if(!empty($CNF['OBJECT_METATAGS']) && !empty($sText)) {
  2561. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  2562. $sText = $oMetatags->metaParse($aContentInfo[$CNF['FIELD_ID']], $sText);
  2563. }
  2564. return array(
  2565. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  2566. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  2567. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  2568. 'url' => $sUrl,
  2569. 'title' => '',
  2570. 'text' => $sText,
  2571. 'images' => array(),
  2572. 'videos' => array()
  2573. );
  2574. }
  2575. protected function _isAllowedPin($aEvent, $bPerform = false)
  2576. {
  2577. $iUserId = (int)$this->getUserId();
  2578. if($iUserId == 0)
  2579. return false;
  2580. if(isAdmin() || (int)$aEvent['owner_id'] == $iUserId || ((int)$aEvent['owner_id'] == 0 && $this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && (int)$aEvent['object_id'] == $iUserId))
  2581. return true;
  2582. $aCheckResult = checkActionModule($iUserId, 'pin', $this->getName(), $bPerform);
  2583. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  2584. if($oProfileOwner !== false)
  2585. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_pin', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2586. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2587. }
  2588. protected function _isAllowedStick($aEvent, $bPerform = false)
  2589. {
  2590. $iUserId = (int)$this->getUserId();
  2591. if($iUserId == 0)
  2592. return false;
  2593. if(isAdmin())
  2594. return true;
  2595. $aCheckResult = checkActionModule($iUserId, 'stick', $this->getName(), $bPerform);
  2596. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  2597. if($oProfileOwner !== false)
  2598. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_stick', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2599. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2600. }
  2601. protected function _isAllowedPromote($aEvent, $bPerform = false)
  2602. {
  2603. if(isAdmin())
  2604. return true;
  2605. $iUserId = (int)$this->getUserId();
  2606. if($iUserId == 0)
  2607. return false;
  2608. $aCheckResult = checkActionModule($iUserId, 'promote', $this->getName(), $bPerform);
  2609. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  2610. if($oProfileOwner !== false)
  2611. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_promote', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2612. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2613. }
  2614. protected function _addLink(&$oForm)
  2615. {
  2616. $iUserId = $this->getUserId();
  2617. $sLink = $oForm->getCleanValue('url');
  2618. $aMatches = array();
  2619. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  2620. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  2621. $aSiteInfo = bx_get_site_info($sLink, array(
  2622. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  2623. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  2624. ));
  2625. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : _t('_Empty');
  2626. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : _t('_Empty');
  2627. $sMediaUrl = '';
  2628. if(!empty($aSiteInfo['thumbnailUrl']))
  2629. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  2630. else if(!empty($aSiteInfo['OGImage']))
  2631. $sMediaUrl = $aSiteInfo['OGImage'];
  2632. $iMediaId = 0;
  2633. $oStorage = null;
  2634. if(!empty($sMediaUrl)) {
  2635. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . BX_TIMELINE_MEDIA_PHOTO . 's'));
  2636. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  2637. }
  2638. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  2639. if(!empty($iId)) {
  2640. if(!empty($oStorage) && !empty($iMediaId))
  2641. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  2642. return array('id' => $iId, 'item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId));
  2643. }
  2644. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  2645. }
  2646. protected function _deleteLinks($iId)
  2647. {
  2648. $aLinks = $this->_oDb->getLinks($iId);
  2649. if(empty($aLinks) || !is_array($aLinks))
  2650. return;
  2651. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  2652. foreach($aLinks as $aLink)
  2653. if(!empty($aLink['media_id']))
  2654. $oStorage->deleteFile($aLink['media_id']);
  2655. $this->_oDb->deleteLinks($iId);
  2656. }
  2657. protected function _saveMedia($sType, $iId, $aItemIds)
  2658. {
  2659. if(empty($aItemIds) || !is_array($aItemIds))
  2660. return;
  2661. $iUserId = $this->getUserId();
  2662. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  2663. foreach($aItemIds as $iItemId)
  2664. if($this->_oDb->saveMedia($sType, $iId, $iItemId))
  2665. $oStorage->afterUploadCleanup($iItemId, $iUserId);
  2666. }
  2667. protected function _deleteMedia($sType, $iId)
  2668. {
  2669. $aItems = $this->_oDb->getMedia($sType, $iId);
  2670. if(empty($aItems) || !is_array($aItems))
  2671. return;
  2672. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  2673. foreach($aItems as $iItemId)
  2674. $oStorage->deleteFile($iItemId);
  2675. $this->_oDb->deleteMedia($sType, $iId);
  2676. }
  2677. protected function _prepareParams($aParams)
  2678. {
  2679. if(empty($aParams['name']))
  2680. $aParams['name'] = '';
  2681. if(empty($aParams['view']))
  2682. $aParams['view'] = BX_TIMELINE_VIEW_DEFAULT;
  2683. if(empty($aParams['type']))
  2684. $aParams['type'] = BX_TIMELINE_TYPE_DEFAULT;
  2685. if(empty($aParams['owner_id']))
  2686. $aParams['owner_id'] = $this->getUserId();
  2687. if(!isset($aParams['start']) || (int)$aParams['start'] < 0)
  2688. $aParams['start'] = 0;
  2689. if(!isset($aParams['per_page']) || (int)$aParams['per_page'] <= 0)
  2690. $aParams['per_page'] = $this->_oConfig->getPerPage();
  2691. if(empty($aParams['timeline']) || (int)$aParams['timeline'] < 0)
  2692. $aParams['timeline'] = 0;
  2693. if(empty($aParams['filter']))
  2694. $aParams['filter'] = BX_TIMELINE_FILTER_ALL;
  2695. if(empty($aParams['modules']) || !is_array($aParams['modules']))
  2696. $aParams['modules'] = array();
  2697. if(empty($aParams['blink']) || !is_array($aParams['blink']))
  2698. $aParams['blink'] = array();
  2699. if($this->_oConfig->isHot())
  2700. $aParams['hot'] = $this->_oDb->getHot();
  2701. $aParams = array_merge($aParams, array(
  2702. 'browse' => 'list',
  2703. 'active' => 1,
  2704. 'hidden' => 0
  2705. ));
  2706. return $aParams;
  2707. }
  2708. protected function _prepareParamsGet()
  2709. {
  2710. $aParams = array();
  2711. $aParams['name'] = bx_get('name');
  2712. $aParams['name'] = $aParams['name'] !== false ? bx_process_input($aParams['name'], BX_DATA_TEXT) : '';
  2713. $aParams['view'] = bx_get('view');
  2714. $aParams['view'] = $aParams['view'] !== false ? bx_process_input($aParams['view'], BX_DATA_TEXT) : BX_TIMELINE_VIEW_DEFAULT;
  2715. $aParams['type'] = bx_get('type');
  2716. $aParams['type'] = $aParams['type'] !== false ? bx_process_input($aParams['type'], BX_DATA_TEXT) : BX_TIMELINE_TYPE_DEFAULT;
  2717. $aParams['owner_id'] = bx_get('owner_id');
  2718. $aParams['owner_id'] = $aParams['owner_id'] !== false ? bx_process_input($aParams['owner_id'], BX_DATA_INT) : $this->getUserId();
  2719. $aParams['start'] = bx_get('start');
  2720. $aParams['start'] = $aParams['start'] !== false ? bx_process_input($aParams['start'], BX_DATA_INT) : 0;
  2721. $aParams['per_page'] = bx_get('per_page');
  2722. $aParams['per_page'] = $aParams['per_page'] !== false ? bx_process_input($aParams['per_page'], BX_DATA_INT) : $this->_oConfig->getPerPage();
  2723. $aParams['timeline'] = bx_get('timeline');
  2724. $aParams['timeline'] = $aParams['timeline'] !== false ? bx_process_input($aParams['timeline'], BX_DATA_INT) : 0;
  2725. $aParams['filter'] = bx_get('filter');
  2726. $aParams['filter'] = $aParams['filter'] !== false ? bx_process_input($aParams['filter'], BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  2727. $aParams['modules'] = bx_get('modules');
  2728. $aParams['modules'] = $aParams['modules'] !== false ? bx_process_input($aParams['modules'], BX_DATA_TEXT) : array();
  2729. $aParams['blink'] = bx_get('blink');
  2730. $aParams['blink'] = $aParams['blink'] !== false ? explode(',', bx_process_input($aParams['blink'], BX_DATA_TEXT)) : array();
  2731. if($this->_oConfig->isHot())
  2732. $aParams['hot'] = $this->_oDb->getHot();
  2733. $aParams = array_merge($aParams, array(
  2734. 'browse' => 'list',
  2735. 'active' => 1,
  2736. 'hidden' => 0,
  2737. 'dynamic_mode' => true,
  2738. ));
  2739. return $aParams;
  2740. }
  2741. protected function _prepareTextForSave($s)
  2742. {
  2743. return bx_process_input($s, BX_DATA_HTML);
  2744. }
  2745. protected function _getFieldValue($sField, $iContentId)
  2746. {
  2747. $CNF = &$this->_oConfig->CNF;
  2748. if(empty($CNF[$sField]))
  2749. return false;
  2750. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2751. if(empty($aEvent) || empty($aEvent[$CNF[$sField]]))
  2752. return false;
  2753. return $aEvent[$CNF[$sField]];
  2754. }
  2755. }
  2756. /** @} */