BxTimelineModule.php 124 KB

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