BxTimelineModule.php 126 KB

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