BxTimelineModule.php 125 KB

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