BxTimelineModule.php 147 KB

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