BxTimelineModule.php 189 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889
  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. /**
  14. * SLTMODE - Silent mode:
  15. * It is needed for alert sending module to tell that the alert should be ignored
  16. * with Timeline module completely or partially. Available values:
  17. * 1. disabled (global, value = 0) - all events are registered;
  18. * 2. absolute (global, value = 1) - alert isn't registered which means that event won't appear in timelines at all;
  19. * 3. absolute (for Timeline only, value = 21) - the same as global absolute.
  20. * 4. partial registration might be added in the future versions.
  21. *
  22. * @see BxBaseModNotificationsModule and BxTimelineResponse::response - 'silent_mode' parameter in Alerts Extras array.
  23. */
  24. define('BX_TIMELINE_SLTMODE_ABSOLUTE', 21);
  25. define('BX_TIMELINE_NAME_VIEWS_DB', 'views_db'); //--- Dynamic browsing feeds.
  26. define('BX_TIMELINE_TYPE_ITEM', 'view_item');
  27. define('BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS', 'owner_and_connections');
  28. define('BX_TIMELINE_TYPE_CHANNELS', 'channels'); //--- Followed channels only.
  29. define('BX_TIMELINE_TYPE_FEED', 'feed'); //--- Owner and folloved contexts excluding channels.
  30. define('BX_TIMELINE_TYPE_HOT', 'hot'); //--- Aggrigated hot content.
  31. define('BX_TIMELINE_TYPE_DEFAULT', BX_BASE_MOD_NTFS_TYPE_OWNER);
  32. define('BX_TIMELINE_VIEW_ITEM', 'item');
  33. define('BX_TIMELINE_VIEW_TIMELINE', 'timeline');
  34. define('BX_TIMELINE_VIEW_OUTLINE', 'outline');
  35. define('BX_TIMELINE_VIEW_SEARCH', 'search');
  36. define('BX_TIMELINE_VIEW_DEFAULT', BX_TIMELINE_VIEW_OUTLINE);
  37. define('BX_TIMELINE_FILTER_ALL', 'all');
  38. define('BX_TIMELINE_FILTER_OWNER', 'owner');
  39. define('BX_TIMELINE_FILTER_OTHER', 'other');
  40. define('BX_TIMELINE_FILTER_OTHER_VIEWER', 'other_viewer');
  41. define('BX_TIMELINE_PARSE_TYPE_POST', 'post');
  42. define('BX_TIMELINE_PARSE_TYPE_REPOST', 'repost');
  43. define('BX_TIMELINE_PARSE_TYPE_DEFAULT', BX_TIMELINE_PARSE_TYPE_POST);
  44. define('BX_TIMELINE_STATUS_ACTIVE', 'active');
  45. define('BX_TIMELINE_STATUS_AWAITING', 'awaiting');
  46. define('BX_TIMELINE_STATUS_FAILED', 'failed');
  47. define('BX_TIMELINE_STATUS_HIDDEN', 'hidden');
  48. define('BX_TIMELINE_STATUS_DELETED', 'deleted');
  49. //--- Video Auto Play
  50. define('BX_TIMELINE_VAP_OFF', 'off');
  51. define('BX_TIMELINE_VAP_ON_MUTE', 'on_mute');
  52. define('BX_TIMELINE_VAP_ON', 'on');
  53. //--- Media Layouts
  54. define('BX_TIMELINE_ML_SINGLE', 'single');
  55. define('BX_TIMELINE_ML_GALLERY', 'gallery');
  56. define('BX_TIMELINE_ML_SHOWCASE', 'showcase');
  57. //--- Default Attachments Media Layout
  58. define('BX_TIMELINE_AML_DEFAULT', BX_TIMELINE_ML_GALLERY);
  59. class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolContentInfoService
  60. {
  61. protected $_sJsPostObject;
  62. protected $_sJsViewObject;
  63. protected $_aPostElements;
  64. protected $_sJsOutlineObject;
  65. protected $_sDividerTemplate;
  66. protected $_sBalloonTemplate;
  67. protected $_sCmtPostTemplate;
  68. protected $_sCmtViewTemplate;
  69. protected $_sCmtTemplate;
  70. /**
  71. * Constructor
  72. */
  73. function __construct($aModule)
  74. {
  75. parent::__construct($aModule);
  76. }
  77. /**
  78. * ACTION METHODS
  79. */
  80. public function actionGetContexts($iLimit = 20)
  81. {
  82. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  83. if(!$oConnection)
  84. return echoJson(array());
  85. $iProfileId = bx_get_logged_profile_id();
  86. $aConnected = $oConnection->getConnectedContent($iProfileId);
  87. $sTerm = bx_get('term');
  88. if(!$sTerm)
  89. return array_slice($aConnected, 0, $iLimit);
  90. $aResults = array();
  91. $aModules = bx_srv('system', 'get_profiles_modules', array(false), 'TemplServiceProfiles');
  92. foreach($aModules as $aModule) {
  93. if(!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  94. continue;
  95. $aContexts = bx_srv($aModule['name'], 'profiles_search', array($sTerm, PHP_INT_MAX));
  96. foreach($aContexts as $aContext) {
  97. if(!in_array($aContext['value'], $aConnected))
  98. continue;
  99. $aResults[] = $aContext;
  100. }
  101. }
  102. usort($aResults, function($r1, $r2) {
  103. return strcmp($r1['label'], $r2['label']);
  104. });
  105. echoJson(array_slice($aResults, 0, $iLimit));
  106. }
  107. public function actionVideo($iEventId, $iVideoId)
  108. {
  109. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iEventId));
  110. if(empty($aEvent) || !is_array($aEvent))
  111. return;
  112. $aData = $this->_oTemplate->getDataCached($aEvent);
  113. if($aData === false || !isset($aData['content']['videos'][$iVideoId]))
  114. return;
  115. $oTemplate = BxDolTemplate::getInstance();
  116. $oTemplate->addJs(array(
  117. 'embedly-player.min.js'
  118. ));
  119. $oTemplate->setPageNameIndex (BX_PAGE_EMBED);
  120. $oTemplate->setPageContent ('page_main_code', $this->_oTemplate->getVideo($aEvent, $aData['content']['videos'][$iVideoId]));
  121. $oTemplate->getPageCode();
  122. }
  123. public function actionPost()
  124. {
  125. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  126. $mixedAllowed = $this->isAllowedPost(true);
  127. if($mixedAllowed !== true)
  128. return echoJson(array('message' => strip_tags($mixedAllowed)));
  129. echoJson($this->getFormPost());
  130. }
  131. public function actionEdit($iId)
  132. {
  133. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  134. $aBrowseParams = array();
  135. if(bx_get('bp') !== false)
  136. $aBrowseParams = $this->_oConfig->getBrowseParams(bx_process_input(bx_get('bp')));
  137. $mixedAllowed = $this->isAllowedPost(true);
  138. if($mixedAllowed !== true)
  139. return echoJson(array('message' => strip_tags($mixedAllowed)));
  140. echoJson($this->getFormEdit($iId, array('dynamic_mode' => true), $aBrowseParams));
  141. }
  142. function actionPin()
  143. {
  144. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  145. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  146. if(empty($aEvent) || !is_array($aEvent))
  147. return echoJson(array('code' => 1));
  148. $aParams = $this->_prepareParamsGet();
  149. $this->_iOwnerId = $aParams['owner_id'];
  150. $mixedAllowed = $this->{'isAllowed' . ((int)$aEvent['pinned'] == 0 ? 'Pin' : 'Unpin')}($aEvent, true);
  151. if($mixedAllowed !== true)
  152. return echoJson(array('code' => 2, 'message' => strip_tags($mixedAllowed)));
  153. $aEvent['pinned'] = (int)$aEvent['pinned'] == 0 ? time() : 0;
  154. if(!$this->_oDb->updateEvent(array('pinned' => $aEvent['pinned']), array('id' => $iId)))
  155. return echoJson(array('code' => 3));
  156. echoJson(array(
  157. 'code' => 0,
  158. 'id' => $iId,
  159. 'eval' => $this->_oConfig->getJsObjectView($aParams) . '.onPinPost(oData)'
  160. ));
  161. }
  162. function actionStick()
  163. {
  164. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  165. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  166. if(empty($aEvent) || !is_array($aEvent))
  167. return echoJson(array('code' => 1));
  168. $aParams = $this->_prepareParamsGet();
  169. $this->_iOwnerId = $aParams['owner_id'];
  170. $mixedAllowed = $this->{'isAllowed' . ((int)$aEvent['sticked'] == 0 ? 'Stick' : 'Unstick')}($aEvent, true);
  171. if($mixedAllowed !== true)
  172. return echoJson(array('code' => 2, 'message' => strip_tags($mixedAllowed)));
  173. $aEvent['sticked'] = (int)$aEvent['sticked'] == 0 ? time() : 0;
  174. if(!$this->_oDb->updateEvent(array('sticked' => $aEvent['sticked']), array('id' => $iId)))
  175. return echoJson(array('code' => 3));
  176. bx_audit(
  177. $iId,
  178. $this->getName(),
  179. '_sys_audit_action_' . ((int)$aEvent['sticked'] == 0 ? 'stick' : 'unstick'),
  180. $this->_prepareAuditParams($aEvent, false)
  181. );
  182. echoJson(array(
  183. 'code' => 0,
  184. 'id' => $iId,
  185. 'eval' => $this->_oConfig->getJsObjectView($aParams) . '.onStickPost(oData)'
  186. ));
  187. }
  188. function actionPromote()
  189. {
  190. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  191. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  192. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  193. $sAction = (int)$aEvent['promoted'] == 0 ? 'promote' : 'unpromote';
  194. $mixedAllowed = $this->{'isAllowed' . ucfirst($sAction)}($aEvent, true);
  195. if($mixedAllowed !== true)
  196. return echoJson(array('code' => 1, 'message' => strip_tags($mixedAllowed)));
  197. $aEvent['promoted'] = (int)$aEvent['promoted'] == 0 ? time() : 0;
  198. if(!$this->_oDb->updateEvent(array('promoted' => $aEvent['promoted']), array('id' => $iId)))
  199. return echoJson(array('code' => 2));
  200. bx_alert($this->_oConfig->getObject('alert'), $sAction . 'd', $iId, (int)$this->getUserId(), array(
  201. 'owner_id' => $aEvent['owner_id'],
  202. 'object_id' => $aEvent['object_id'],
  203. 'object_author_id' => $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $aEvent['owner_id'] : $aEvent['object_id']
  204. ));
  205. bx_audit(
  206. $iId,
  207. $this->getName(),
  208. '_sys_audit_action_' . ((int)$aEvent['promoted'] == 0 ? 'promote' : 'unpromote'),
  209. $this->_prepareAuditParams($aEvent, false)
  210. );
  211. echoJson(array(
  212. 'code' => 0,
  213. 'message' => _t('_bx_timeline_txt_msg_performed_action')
  214. ));
  215. }
  216. function actionMute()
  217. {
  218. $CNF = &$this->_oConfig->CNF;
  219. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  220. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  221. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  222. $mixedAllowed = $this->isAllowedMute($aEvent, true);
  223. if($mixedAllowed !== true)
  224. return echoJson(array('code' => 1, 'message' => strip_tags($mixedAllowed)));
  225. $iAuthor = (int)$aEvent[$CNF['FIELD_OWNER_ID']];
  226. if(!$this->_oConfig->isSystem($aEvent['type'], $aEvent['action']))
  227. $iAuthor = (int)$aEvent[$CNF['FIELD_OBJECT_ID']];
  228. if(!$this->getConnectionMuteObject()->addConnection($this->_iProfileId, $iAuthor))
  229. return echoJson(array('code' => 2));
  230. bx_alert($this->_oConfig->getObject('alert'), 'muted', $iAuthor, $this->_iProfileId, array(
  231. 'owner_id' => $aEvent['owner_id'],
  232. 'object_id' => $aEvent['object_id'],
  233. 'object_author_id' => $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $aEvent['owner_id'] : $aEvent['object_id']
  234. ));
  235. echoJson(array('code' => 0, 'message' => _t('_bx_timeline_txt_msg_performed_action'), 'reload' => 1));
  236. }
  237. function actionDelete()
  238. {
  239. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  240. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  241. if(empty($aEvent) || !is_array($aEvent))
  242. return echoJson(array('code' => 1));
  243. $aParams = $this->_prepareParamsGet();
  244. $this->_iOwnerId = $aParams['owner_id'];
  245. $mixedAllowed = $this->isAllowedDelete($aEvent, true);
  246. if($mixedAllowed !== true)
  247. return echoJson(array('code' => 2, 'message' => strip_tags($mixedAllowed)));
  248. if(!$this->deleteEvent($aEvent))
  249. return echoJson(array('code' => 3));
  250. echoJson(array(
  251. 'code' => 0,
  252. 'id' => $aEvent['id'],
  253. 'eval' => $this->_oConfig->getJsObjectView($aParams) . '.onDeletePost(oData)'
  254. ));
  255. }
  256. public function actionRepost()
  257. {
  258. $iAuthorId = $this->getUserId();
  259. $iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  260. $sType = bx_process_input(bx_get('type'), BX_DATA_TEXT);
  261. $sAction = bx_process_input(bx_get('action'), BX_DATA_TEXT);
  262. $iObjectId = bx_process_input(bx_get('object_id'), BX_DATA_INT);
  263. $aResult = $this->serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId);
  264. if(!empty($aResult) && is_array($aResult))
  265. return echoJson($aResult);
  266. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  267. $sCounter = $this->_oTemplate->getRepostCounter($aReposted);
  268. echoJson(array(
  269. 'code' => 0,
  270. 'message' => _t('_bx_timeline_txt_msg_success_repost'),
  271. 'count' => $aReposted['reposts'],
  272. 'countf' => (int)$aReposted['reposts'] > 0 ? $this->_oTemplate->getRepostCounterLabel($aReposted['reposts']) : '',
  273. 'counter' => $sCounter,
  274. 'disabled' => true
  275. ));
  276. }
  277. public function actionRepostTo()
  278. {
  279. $iReposterId = bx_process_input(bx_get('reposter_id'), BX_DATA_INT);
  280. if($iReposterId != $this->getUserId())
  281. return;
  282. $sType = bx_process_input(bx_get('type'), BX_DATA_TEXT);
  283. $sAction = bx_process_input(bx_get('action'), BX_DATA_TEXT);
  284. $iObjectId = bx_process_input(bx_get('object_id'), BX_DATA_INT);
  285. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_repost_to'), $this->_oConfig->getObject('form_display_repost_to_browse'));
  286. $oForm->initChecker(array(
  287. 'reposter_id' => $iReposterId,
  288. 'type' => $sType,
  289. 'action' => $sAction,
  290. 'object_id' => $iObjectId
  291. ));
  292. if($oForm->isSubmitted()) {
  293. if(!$oForm->isValid())
  294. return echoJson(array('popup' => array(
  295. 'html' => BxTemplFunctions::getInstance()->transBox($this->_oConfig->getHtmlIds('repost', 'to_popup'), $this->_oTemplate->getRepostTo($oForm)),
  296. 'options' => array('closeOnOuterClick' => false, 'removeOnClose' => true)
  297. )));
  298. $aContexts = array();
  299. if(($aContextsSearch = $oForm->getCleanValue('search')) !== false)
  300. $aContexts = array_merge($aContexts, $aContextsSearch);
  301. if(($aContextsList = $oForm->getCleanValue('list')) !== false)
  302. $aContexts = array_merge($aContexts, $aContextsList);
  303. $aContexts = array_unique($aContexts);
  304. if(empty($aContexts) || !is_array($aContexts))
  305. return echoJson(array());
  306. foreach($aContexts as $iContextId)
  307. $this->serviceRepost($iReposterId, $iContextId, $sType, $sAction, $iObjectId);
  308. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  309. $sCounter = $this->_oTemplate->getRepostCounter($aReposted);
  310. return echoJson(array(
  311. 'code' => 0,
  312. 'message' => _t('_bx_timeline_txt_msg_success_repost'),
  313. 'count' => $aReposted['reposts'],
  314. 'countf' => (int)$aReposted['reposts'] > 0 ? $this->_oTemplate->getRepostCounterLabel($aReposted['reposts']) : '',
  315. 'counter' => $sCounter,
  316. ));
  317. }
  318. echo $this->_oTemplate->getRepostTo($oForm);
  319. }
  320. function actionGetView()
  321. {
  322. $aParams = $this->_prepareParamsGet();
  323. $sContent = $this->_oTemplate->getViewBlock($aParams);
  324. if(empty($sContent))
  325. return echoJson(array());
  326. if(!empty($aParams['type']))
  327. $this->_oConfig->setUserChoice(array('type' => $aParams['type']));
  328. echoJson(array(
  329. 'code' => 0,
  330. 'content' => $sContent,
  331. ));
  332. }
  333. function actionGetViewFilters()
  334. {
  335. $aParams = $this->_prepareParamsGet();
  336. $sContent = $this->_oTemplate->getViewFilters($aParams);
  337. if(empty($sContent))
  338. return echoJson([]);
  339. echoJson([
  340. 'code' => 0,
  341. 'popup' => [
  342. 'html' => $sContent,
  343. 'options' => [
  344. 'closeOnOuterClick' => true,
  345. 'removeOnClose' => false,
  346. ]
  347. ],
  348. ]);
  349. }
  350. function actionGetPost()
  351. {
  352. $aParams = $this->_prepareParamsGet();
  353. $aParams['dynamic_mode'] = true;
  354. $this->_iOwnerId = $aParams['owner_id'];
  355. $sJsObject = '';
  356. if(bx_get('js_object') !== false)
  357. $sJsObject = bx_process_input(bx_get('js_object'));
  358. if(empty($sJsObject))
  359. $sJsObject = $this->_oConfig->getJsObject('post');
  360. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => bx_process_input(bx_get('id'), BX_DATA_INT)));
  361. if(empty($aEvent) || !is_array($aEvent))
  362. return echoJson(array());
  363. /**
  364. * Note. Disabled for now, because Own posts on Timelines of Following members
  365. * became visible on posts' author Dashboard Timeline.
  366. */
  367. /*
  368. $bAfpsLoading = (int)bx_get('afps_loading') === 1;
  369. if($bAfpsLoading && $this->_iOwnerId != $aEvent['owner_id'])
  370. return echoJson(array('message' => _t('_bx_timeline_txt_msg_posted')));
  371. */
  372. $aResult = array(
  373. 'id' => $aEvent['id'],
  374. 'name' => $aParams['name'],
  375. 'view' => $aParams['view'],
  376. 'type' => $aParams['type'],
  377. 'item' => $this->_oTemplate->getPost($aEvent, $aParams),
  378. 'eval' => $sJsObject . "._onGetPost(oData)"
  379. );
  380. bx_alert($this->getName(), 'on_get_post', 0, 0, array(
  381. 'params' => $aParams,
  382. 'override_result' => &$aResult,
  383. ));
  384. echoJson($aResult);
  385. }
  386. function actionGetPosts()
  387. {
  388. $aParams = $this->_prepareParamsGet();
  389. list($sItems, $sLoadMore, $sBack, $sEmpty, $iEvent, $bEventsToLoad) = $this->_oTemplate->getPosts($aParams);
  390. echoJson(array(
  391. 'view' => $aParams['view'],
  392. 'items' => $sItems,
  393. 'load_more' => $sLoadMore,
  394. 'back' => $sBack,
  395. 'empty' => $sEmpty,
  396. 'events_to_load' => $bEventsToLoad,
  397. 'eval' => $this->_oConfig->getJsObjectView($aParams) . "._onGetPosts(oData)"
  398. ));
  399. }
  400. public function actionGetPostForm()
  401. {
  402. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  403. $sType = bx_process_input(bx_get('type'));
  404. echoJson($this->getFormPost(array(
  405. 'type' => $sType,
  406. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  407. )));
  408. }
  409. public function actionGetEditForm($iId)
  410. {
  411. $aParams = $this->_prepareParamsGet();
  412. $this->_iOwnerId = $aParams['owner_id'];
  413. echoJson($this->getFormEdit($iId, array('dynamic_mode' => true), $aParams));
  414. }
  415. public function actionGetComments()
  416. {
  417. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  418. $sSystem = bx_process_input(bx_get('system'), BX_DATA_TEXT);
  419. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  420. $sComments = $this->_oTemplate->getComments($sSystem, $iId, array('dynamic_mode' => true));
  421. echoJson(array('content' => $sComments));
  422. }
  423. public function actionAddAttachLink()
  424. {
  425. $sUrl = bx_process_input(bx_get('url'));
  426. if(empty($sUrl))
  427. return echoJson(array());
  428. $sHeader = 'Content-Type';
  429. $aHeaders = get_headers($sUrl, 1);
  430. if(!empty($aHeaders) && is_array($aHeaders) && !empty($aHeaders[$sHeader])) {
  431. $mixedContentType = $aHeaders[$sHeader];
  432. if(!is_array($mixedContentType))
  433. $mixedContentType = array($mixedContentType);
  434. foreach($mixedContentType as $sContentType)
  435. if(strpos($sContentType, 'image') !== false)
  436. return echoJson(array());
  437. }
  438. $iEventId = 0;
  439. if(bx_get('event_id') !== false)
  440. $iEventId = (int)bx_get('event_id');
  441. echoJson($this->addAttachLink(array(
  442. 'event_id' => $iEventId,
  443. 'url' => $sUrl
  444. )));
  445. }
  446. public function actionDeleteAttachLink()
  447. {
  448. $iUserId = $this->getUserId();
  449. $iLinkId = bx_process_input(bx_get('id'), BX_DATA_INT);
  450. if(empty($iLinkId))
  451. return echoJson(array());
  452. $aLink = $this->_oDb->getLinksBy(array('type' => 'id', 'id' => $iLinkId, 'profile_id' => $iUserId));
  453. if(empty($aLink) || !is_array($aLink))
  454. return echoJson(array());
  455. if(!empty($aLink['media_id']))
  456. BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'))->deleteFile($aLink['media_id']);
  457. $aResult = array();
  458. if($this->_oDb->deleteLink($iLinkId))
  459. $aResult = array('code' => 0);
  460. else
  461. $aResult = array('code' => 1, 'message' => _t('_bx_timeline_form_post_input_link_err_delete'));
  462. echoJson($aResult);
  463. }
  464. public function actionGetAttachLinkForm()
  465. {
  466. $iEventId = 0;
  467. if(bx_get('event_id') !== false)
  468. $iEventId = (int)bx_get('event_id');
  469. echo $this->_oTemplate->getAttachLinkForm($iEventId);
  470. }
  471. public function actionSubmitAttachLinkForm()
  472. {
  473. echoJson($this->getFormAttachLink());
  474. }
  475. public function actionGetRepostedBy()
  476. {
  477. $iRepostedId = bx_process_input(bx_get('id'), BX_DATA_INT);
  478. echo $this->_oTemplate->getRepostedBy($iRepostedId);
  479. }
  480. public function actionGetItemBrief()
  481. {
  482. $aParams = $this->_prepareParamsGet();
  483. $iEvent = bx_process_input(bx_get('id'), BX_DATA_INT);
  484. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iEvent));
  485. if(empty($aEvent) || !is_array($aEvent)) {
  486. echo MsgBox(_t('_Empty'));
  487. return;
  488. }
  489. if(!$this->isAllowedView($aEvent)) {
  490. echo MsgBox(_t('_sys_access_denied_to_private_content'));
  491. return;
  492. }
  493. $sName = $this->_oConfig->getHtmlIdView('item_popup', $aParams, array('whole' => false, 'hash' => false)) . $iEvent;
  494. $sTitle = _t('_bx_timeline_page_title_item_brief');
  495. $sContent = BxDolPage::getObjectInstance($this->_oConfig->getObject('page_item_brief'), $this->_oTemplate)->getCodeDynamic();
  496. echo PopupBox($sName, $sTitle, $sContent, true);
  497. }
  498. public function actionGetJumpTo()
  499. {
  500. $aParams = $this->_prepareParamsGet();
  501. $this->_iOwnerId = $aParams['owner_id'];
  502. $sJsObjectView = $this->_oConfig->getJsObjectView($aParams);
  503. echoJson(array(
  504. 'content' => $this->_oTemplate->getJumpTo($aParams),
  505. 'eval' => $sJsObjectView . '.onGetJumpTo(oData)'
  506. ));
  507. }
  508. public function actionResumeLiveUpdate()
  509. {
  510. $aParams = $this->_prepareParamsGet();
  511. $sKey = $this->_oConfig->getLiveUpdateKey($aParams);
  512. bx_import('BxDolSession');
  513. BxDolSession::getInstance()->unsetValue($sKey);
  514. }
  515. public function actionPauseLiveUpdate()
  516. {
  517. $aParams = $this->_prepareParamsGet();
  518. $sKey = $this->_oConfig->getLiveUpdateKey($aParams);
  519. bx_import('BxDolSession');
  520. BxDolSession::getInstance()->setValue($sKey, 1);
  521. }
  522. function actionRss()
  523. {
  524. $CNF = &$this->_oConfig->CNF;
  525. $aArgs = func_get_args();
  526. $sType = array_shift($aArgs);
  527. $iOwnerId = 0;
  528. switch($sType) {
  529. case BX_BASE_MOD_NTFS_TYPE_OWNER:
  530. $iOwnerId = array_shift($aArgs);
  531. $sOwnerName = $this->getObjectUser($iOwnerId)->getDisplayName();
  532. $sRssCaption = _t('_bx_timeline_txt_rss_caption', $sOwnerName);
  533. $sRssLink = $this->_oConfig->getViewUrl($iOwnerId);
  534. break;
  535. case BX_BASE_MOD_NTFS_TYPE_PUBLIC:
  536. $sRssCaption = _t('_bx_timeline_page_title_view_home');
  537. $sRssLink = $this->_oConfig->getHomeViewUrl();
  538. break;
  539. }
  540. $aParams = $this->_prepareParams(array(
  541. 'view' => BX_TIMELINE_VIEW_DEFAULT,
  542. 'type' => $sType,
  543. 'owner_id' => $iOwnerId,
  544. 'start' => 0,
  545. 'per_page' => $this->_oConfig->getRssLength(),
  546. 'timeline' => 0,
  547. 'filter' => '',
  548. 'modules' => array()
  549. ));
  550. $aEvents = $this->_oDb->getEvents($aParams);
  551. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->getObject('privacy_view'));
  552. $aRssData = array();
  553. foreach($aEvents as $aEvent) {
  554. if(empty($aEvent['title']))
  555. continue;
  556. $iEventId = (int)$aEvent[$CNF['FIELD_ID']];
  557. $sEventFieldAuthor = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? 'owner_id' : 'object_id';
  558. if($oPrivacy) {
  559. $oPrivacy->setTableFieldAuthor($sEventFieldAuthor);
  560. if(!$oPrivacy->check($iEventId))
  561. continue;
  562. }
  563. $iOwner = $aEvent[$sEventFieldAuthor];
  564. $oOwner = BxDolProfile::getInstanceMagic($iOwner);
  565. $aRssData[$iEventId] = array(
  566. 'UnitID' => $iEventId,
  567. 'UnitTitle' => $aEvent['title'],
  568. 'UnitLink' => $this->_oConfig->getItemViewUrl($aEvent),
  569. 'UnitDesc' => bx_replace_markers($aEvent['description'], array(
  570. 'profile_name' => $oOwner->getDisplayName()
  571. )),
  572. 'UnitDateTimeUTS' => $aEvent['date'],
  573. );
  574. }
  575. $oRss = new BxDolRssFactory();
  576. header('Content-Type: application/xml; charset=utf-8');
  577. echo $oRss->GenRssByData($aRssData, $sRssCaption, $sRssLink);
  578. }
  579. /**
  580. * SERVICE METHODS
  581. */
  582. public function serviceGetSafeServices()
  583. {
  584. $a = parent::serviceGetSafeServices();
  585. return array_merge($a, array (
  586. 'GetCreatePostForm' => '',
  587. 'GetSearchResultUnit' => '',
  588. 'GetBlockPost' => '',
  589. 'GetBlockPostProfile' => '',
  590. 'GetBlockPostHome' => '',
  591. 'GetBlockPostAccount' => '',
  592. 'GetBlockView' => '',
  593. 'GetBlockViewOutline' => '',
  594. 'GetBlockViewProfile' => '',
  595. 'GetBlockViewProfileOutline' => '',
  596. 'GetBlockViewsTimeline' => '',
  597. 'GetBlockViewsOutline' => '',
  598. 'GetBlockViewHome' => '',
  599. 'GetBlockViewHomeOutline' => '',
  600. 'GetBlockViewHot' => '',
  601. 'GetBlockViewHotOutline' => '',
  602. 'GetBlockViewAccount' => '',
  603. 'GetBlockViewAccountOutline' => '',
  604. ));
  605. }
  606. public function serviceFeedsMenuAdd($mixedModule = false)
  607. {
  608. $sSetName = $this->_oConfig->getObject('menu_set_feeds');
  609. $iOrder = $this->_oDb->getMenuItemMaxOrder($sSetName);
  610. $aModules = !empty($mixedModule) ? [$this->_oDb->getModuleByName($mixedModule)] : bx_srv('system', 'get_modules_by_type', ['context']);
  611. foreach($aModules as $aModule) {
  612. $sModuleName = $aModule['name'];
  613. $sModuleUri = $aModule['uri'];
  614. if($sModuleName == 'system' && $sModuleUri == 'system')
  615. continue;
  616. $iMenuItem = $this->_oDb->getMenuItemId($sSetName, $sModuleUri);
  617. if(!empty($iMenuItem))
  618. continue;
  619. $sTitleKey = '_' . $sModuleName;
  620. if(strcmp($sTitleKey, _t($sTitleKey)) == 0)
  621. $sTitleKey = $aModule['title'];
  622. $this->_oDb->insertMenuItem($sSetName, $sModuleName, $sModuleUri, $sTitleKey, ++$iOrder);
  623. }
  624. return true;
  625. }
  626. public function serviceFeedsMenuDelete($mixedModule = false)
  627. {
  628. $sSetName = $this->_oConfig->getObject('menu_set_feeds');
  629. $aModules = !empty($mixedModule) ? [$this->_oDb->getModuleByName($mixedModule)] : bx_srv('system', 'get_modules_by_type', ['context']);
  630. foreach($aModules as $aModule)
  631. $this->_oDb->deleteMenuItem($sSetName, $aModule['uri']);
  632. return true;
  633. }
  634. /**
  635. * @page service Service Calls
  636. * @section bx_timeline Timeline
  637. * @subsection bx_timeline-other Other
  638. * @subsubsection bx_timeline-get_content_owner_profile_id get_content_owner_profile_id
  639. *
  640. * @code bx_srv('bx_timeline', 'get_content_owner_profile_id', [...]); @endcode
  641. *
  642. * Get event's owner profile id.
  643. *
  644. * @param $mixedEvent integer value with event ID or an array with event info.
  645. * @return event's owner profile id.
  646. *
  647. * @see BxTimelineModule::serviceGetContentOwnerProfileId
  648. */
  649. /**
  650. * @ref bx_timeline-get_content_owner_profile_id "get_content_owner_profile_id"
  651. */
  652. public function serviceGetContentOwnerProfileId($mixedEvent)
  653. {
  654. $CNF = &$this->_oConfig->CNF;
  655. $iProfile = (int)bx_get_logged_profile_id();
  656. if(empty($mixedEvent))
  657. return $iProfile;
  658. if(!is_array($mixedEvent))
  659. $mixedEvent = $this->_oDb->getContentInfoById((int)$mixedEvent);
  660. if(empty($mixedEvent) || !is_array($mixedEvent) || !isset($mixedEvent[$CNF['FIELD_SYSTEM']]))
  661. return $iProfile;
  662. if((int)$mixedEvent[$CNF['FIELD_SYSTEM']] == 0)
  663. return (int)$mixedEvent[$CNF['FIELD_OBJECT_ID']];
  664. if(!empty($mixedEvent['object_owner_id']))
  665. return (int)$mixedEvent['object_owner_id'];
  666. if(!empty($mixedEvent['content'])) {
  667. $aContent = unserialize($mixedEvent['content']);
  668. if(!empty($aContent) && is_array($aContent) && !empty($aContent['object_author_id']))
  669. return (int)$aContent['object_author_id'];
  670. }
  671. $aEventData = $this->_oTemplate->getData($mixedEvent);
  672. if(!empty($aEventData) && is_array($aEventData) && !empty($aEventData['object_owner_id']))
  673. return (int)$aEventData['object_owner_id'];
  674. return $iProfile;
  675. }
  676. /**
  677. * @page service Service Calls
  678. * @section bx_timeline Timeline
  679. * @subsection bx_timeline-other Other
  680. * @subsubsection bx_timeline-get_create_post_form get_create_post_form
  681. *
  682. * @code bx_srv('bx_timeline', 'get_create_post_form', [...]); @endcode
  683. *
  684. * Get form code for add content. Is needed for United Post Form.
  685. *
  686. * @param $aParams optional array with parameters(display name, etc)
  687. * @return form code or error
  688. *
  689. * @see BxTimelineModule::serviceGetCreatePostForm
  690. */
  691. /**
  692. * @ref bx_timeline-get_create_post_form "get_create_post_form"
  693. */
  694. public function serviceGetCreatePostForm($aParams = array())
  695. {
  696. $aParams = array_merge($this->_aFormParams, $aParams);
  697. $bContext = $aParams['context_id'] !== false;
  698. $this->_iOwnerId = $bContext ? abs($aParams['context_id']) : 0;
  699. $oForm = $this->serviceGetObjectForm('add', $aParams);
  700. if(!$oForm)
  701. return '';
  702. $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  703. $aParams['form_display'] = 'form_display_post_add_public';
  704. if($bContext) {
  705. if($aParams['context_id'] < 0) {
  706. $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_OWNER;
  707. $aParams['form_display'] = 'form_display_post_add_profile';
  708. }
  709. else {
  710. $aParams['type'] = BX_TIMELINE_TYPE_FEED;
  711. $aParams['form_display'] = 'form_display_post_add';
  712. }
  713. }
  714. if(!empty($aParams['display']))
  715. $aParams['form_display'] = $aParams['display'];
  716. $aResult = $this->getFormPost($aParams);
  717. if(!empty($aResult['form'])) {
  718. $bDynamicMode = isset($aParams['dynamic_mode']) && $aParams['dynamic_mode'];
  719. $sCode = '';
  720. $sCode .= $this->_oTemplate->getJsCodePost($this->_iOwnerId, $aParams, true, $bDynamicMode);
  721. $sCode .= $aResult['form'];
  722. return $sCode;
  723. }
  724. if(!empty($aResult['message']))
  725. return $aResult['message'];
  726. return '';
  727. }
  728. /**
  729. * @page service Service Calls
  730. * @section bx_timeline Timeline
  731. * @subsection bx_timeline-other Other
  732. * @subsubsection bx_timeline-get_object_form get_object_form
  733. *
  734. * @code bx_srv('bx_timeline', 'get_object_form', [...]); @endcode
  735. *
  736. * Get form object for add, edit, view or delete the content.
  737. *
  738. * @param $sType 'add' is supported only
  739. * @param $aParams optional array with parameters(display name, etc)
  740. * @return form object or false on error
  741. *
  742. * @see BxTimelineModule::serviceGetObjectForm
  743. */
  744. /**
  745. * @ref bx_timeline-get_object_form "get_object_form"
  746. */
  747. public function serviceGetObjectForm ($sType, $aParams = array())
  748. {
  749. if(!in_array($sType, array('add')))
  750. return false;
  751. $bContext = $aParams['context_id'] !== false;
  752. if($bContext && ($oContextProfile = BxDolProfile::getInstance(abs($aParams['context_id']))) !== false)
  753. if($oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  754. return false;
  755. $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  756. $aParams['form_display'] = 'form_display_post_add_public';
  757. if($bContext) {
  758. if($aParams['context_id'] < 0) {
  759. $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_OWNER;
  760. $aParams['form_display'] = 'form_display_post_add_profile';
  761. }
  762. else {
  763. $aParams['type'] = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  764. $aParams['form_display'] = 'form_display_post_add';
  765. }
  766. }
  767. if(!empty($aParams['display']))
  768. $aParams['form_display'] = $aParams['display'];
  769. $oForm = $this->getFormPostObject($aParams);
  770. bx_alert('system', 'get_object_form', 0, 0, array(
  771. 'module' => $this->_oConfig->getName(),
  772. 'type' => $sType,
  773. 'params' => $aParams,
  774. 'form' => &$oForm
  775. ));
  776. return $oForm;
  777. }
  778. /**
  779. * @page service Service Calls
  780. * @section bx_timeline Timeline
  781. * @subsection get_timeline_post
  782. * @see BxTimelineModule::serviceGetTimelinePost
  783. *
  784. * Get Timeline post. It's needed for Timeline module.
  785. *
  786. * @param $aEvent timeline event array from Timeline module
  787. * @return array in special format which is needed specifically for Timeline module to display the data.
  788. */
  789. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  790. {
  791. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  792. if(empty($aContentInfo) || !is_array($aContentInfo))
  793. return false;
  794. $aEvent = array_merge($aEvent, array(
  795. 'owner_id' => $aContentInfo['owner_id'],
  796. 'object_privacy_view' => $aContentInfo['object_privacy_view']
  797. ));
  798. /*
  799. * Note. For 'Direct Timeline Posts' FIELD_OBJECT_ID contains post's author profile ID.
  800. */
  801. $this->_oConfig->CNF['FIELD_AUTHOR'] = $this->_oConfig->CNF['FIELD_OBJECT_ID'];
  802. return parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  803. }
  804. /**
  805. * @page service Service Calls
  806. * @section bx_timeline Timeline
  807. * @subsection get_timeline_post
  808. * @see BxTimelineModule::serviceGetTimelinePostAllowedView
  809. *
  810. * Check Timeline post's visibility. It's needed for Timeline module, when its events
  811. * are accessed and checked from outside. For example, when they are referenced
  812. * from Channels module.
  813. *
  814. * @param $aEvent timeline event array from Timeline module
  815. * @return mixed value: CHECK_ACTION_RESULT_ALLOWED or text of some error message.
  816. */
  817. public function serviceGetTimelinePostAllowedView($aEvent)
  818. {
  819. $CNF = &$this->_oConfig->CNF;
  820. $iOwnerId = (int)$aEvent[$CNF['FIELD_OWNER_ID']];
  821. if($iOwnerId == 0)
  822. return CHECK_ACTION_RESULT_ALLOWED;
  823. $oOwner = BxDolProfile::getInstance($iOwnerId);
  824. if(!$oOwner)
  825. return CHECK_ACTION_RESULT_ALLOWED;
  826. $sModule = $oOwner->getModule();
  827. $aOwnerInfo = BxDolService::call($sModule, 'get_info', array($oOwner->getContentId(), false));
  828. if(empty($aOwnerInfo) || !is_array($aOwnerInfo))
  829. return CHECK_ACTION_RESULT_ALLOWED;
  830. return BxDolService::call($sModule, 'check_allowed_view_for_profile', array($aOwnerInfo));
  831. }
  832. /**
  833. * @page service Service Calls
  834. * @section bx_timeline Timeline
  835. * @subsection bx_timeline-other Other
  836. * @subsubsection bx_timeline-get_author get_author
  837. *
  838. * @code bx_srv('bx_timeline', 'get_author', [...]); @endcode
  839. *
  840. * Get author ID from content info by content ID. Is used in "Content Info Objects" system.
  841. *
  842. * @param $iContentId integer value with content ID.
  843. * @return integer value with author ID.
  844. *
  845. * @see BxTimelineModule::serviceGetAuthor
  846. */
  847. /**
  848. * @ref bx_timeline-get_author "get_author"
  849. */
  850. public function serviceGetAuthor ($iContentId)
  851. {
  852. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  853. if(empty($aEvent) || !is_array($aEvent))
  854. return 0;
  855. return $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? (int)$aEvent['owner_id'] : (int)$aEvent['object_id'];
  856. }
  857. /**
  858. * @page service Service Calls
  859. * @section bx_timeline Timeline
  860. * @subsection bx_timeline-other Other
  861. * @subsubsection bx_timeline-get_date_changed get_date_changed
  862. *
  863. * @code bx_srv('bx_timeline', 'get_date_changed', [...]); @endcode
  864. *
  865. * Get date when the content was changed last time. Is used in "Content Info Objects" system.
  866. * Note. In case of Timeline event 0 is returned everytime.
  867. *
  868. * @param $iContentId integer value with content ID.
  869. * @return integer value with changing date.
  870. *
  871. * @see BxTimelineModule::serviceGetDateChanged
  872. */
  873. /**
  874. * @ref bx_timeline-get_date_changed "get_date_changed"
  875. */
  876. public function serviceGetDateChanged ($iContentId)
  877. {
  878. return 0;
  879. }
  880. /**
  881. * @page service Service Calls
  882. * @section bx_timeline Timeline
  883. * @subsection bx_timeline-other Other
  884. * @subsubsection bx_timeline-get_link get_link
  885. *
  886. * @code bx_srv('bx_timeline', 'get_link', [...]); @endcode
  887. *
  888. * Get content view page link. Is used in "Content Info Objects" system.
  889. *
  890. * @param $iContentId integer value with content ID.
  891. * @return string value with view page link.
  892. *
  893. * @see BxTimelineModule::serviceGetLink
  894. */
  895. /**
  896. * @ref bx_timeline-get_link "get_link"
  897. */
  898. public function serviceGetLink ($iContentId)
  899. {
  900. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  901. if(empty($aEvent) || !is_array($aEvent))
  902. return '';
  903. return $this->_oConfig->getItemViewUrl($aEvent);
  904. }
  905. /**
  906. * @page service Service Calls
  907. * @section bx_timeline Timeline
  908. * @subsection bx_timeline-other Other
  909. * @subsubsection bx_timeline-get_thumb get_thumb
  910. *
  911. * @code bx_srv('bx_timeline', 'get_thumb', [...]); @endcode
  912. *
  913. * Get content thumbnail link. Is used in "Content Info Objects" system.
  914. * Note. In case of Timeline event an empty string is returned everytime.
  915. *
  916. * @param $iContentId integer value with content ID.
  917. * @param $sTranscoder (optional) string value with transcoder name which should be applied to thumbnail image.
  918. * @return string value with thumbnail link.
  919. *
  920. * @see BxTimelineModule::serviceGetThumb
  921. */
  922. /**
  923. * @ref bx_timeline-get_thumb "get_thumb"
  924. */
  925. public function serviceGetThumb ($iContentId, $sTranscoder = '')
  926. {
  927. return '';
  928. }
  929. /**
  930. * @page service Service Calls
  931. * @section bx_timeline Timeline
  932. * @subsection bx_timeline-other Other
  933. * @subsubsection bx_timeline-get_info get_info
  934. *
  935. * @code bx_srv('bx_timeline', 'get_info', [...]); @endcode
  936. *
  937. * Get content info by content ID. Is used in "Content Info Objects" system.
  938. *
  939. * @param $iContentId integer value with content ID.
  940. * @param $bSearchableFieldsOnly (optional) boolean value determining all info or "searchable fields" only will be returned.
  941. * @return an array with content info. Empty array is returned if something is wrong.
  942. *
  943. * @see BxTimelineModule::serviceGetInfo
  944. */
  945. /**
  946. * @ref bx_timeline-get_info "get_info"
  947. */
  948. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  949. {
  950. $aContentInfo = $this->_oDb->getEvents(array(
  951. 'browse' => 'id',
  952. 'value' => $iContentId)
  953. );
  954. return BxDolContentInfo::formatFields($aContentInfo);
  955. }
  956. /**
  957. * @page service Service Calls
  958. * @section bx_timeline Timeline
  959. * @subsection bx_timeline-other Other
  960. * @subsubsection bx_timeline-get_search_result_unit get_search_result_unit
  961. *
  962. * @code bx_srv('bx_timeline', 'get_search_result_unit', [...]); @endcode
  963. *
  964. * Get search result unit by content ID. Is used in "Content Info Objects" system.
  965. *
  966. * @param $iContentId integer value with content ID.
  967. * @param $sUnitTemplate (optional) string value with template name.
  968. * @return HTML string with search result unit. Empty string is returned if something is wrong.
  969. *
  970. * @see BxTimelineModule::serviceGetSearchResultUnit
  971. */
  972. /**
  973. * @ref bx_timeline-get_search_result_unit "get_search_result_unit"
  974. */
  975. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  976. {
  977. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  978. if(empty($aEvent) || !is_array($aEvent))
  979. return '';
  980. if(empty($sUnitTemplate))
  981. $sUnitTemplate = 'unit.html';
  982. return $this->_oTemplate->unit($aEvent, true, $sUnitTemplate);
  983. }
  984. /**
  985. * @page service Service Calls
  986. * @section bx_timeline Timeline
  987. * @subsection bx_timeline-page_blocks Page Blocks
  988. * @subsubsection bx_timeline-get_block_post get_block_post
  989. *
  990. * @code bx_srv('bx_timeline', 'get_block_post', [...]); @endcode
  991. *
  992. * Get Post block for a separate page.
  993. *
  994. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  995. * @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.
  996. *
  997. * @see BxTimelineModule::serviceGetBlockPost
  998. */
  999. /**
  1000. * @ref bx_timeline-get_block_post "get_block_post"
  1001. */
  1002. public function serviceGetBlockPost($iProfileId = 0)
  1003. {
  1004. if(empty($iProfileId) && bx_get('profile_id') !== false)
  1005. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  1006. if(empty($iProfileId) && isLogged())
  1007. $iProfileId = bx_get_logged_profile_id();
  1008. if(!$iProfileId)
  1009. return array();
  1010. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  1011. return $this->_getBlockPost($iProfileId, array(
  1012. 'type' => $sType,
  1013. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  1014. ));
  1015. }
  1016. /**
  1017. * @page service Service Calls
  1018. * @section bx_timeline Timeline
  1019. * @subsection bx_timeline-page_blocks Page Blocks
  1020. * @subsubsection bx_timeline-get_block_post_profile get_block_post_profile
  1021. *
  1022. * @code bx_srv('bx_timeline', 'get_block_post_profile', [...]); @endcode
  1023. *
  1024. * Get Post block for the Profile page.
  1025. *
  1026. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  1027. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  1028. * @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.
  1029. *
  1030. * @see BxTimelineModule::serviceGetBlockPostProfile
  1031. */
  1032. /**
  1033. * @ref bx_timeline-get_block_post_profile "get_block_post_profile"
  1034. */
  1035. public function serviceGetBlockPostProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0)
  1036. {
  1037. if(empty($sProfileModule))
  1038. return array();
  1039. if(empty($iProfileContentId) && bx_get('id') !== false)
  1040. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1041. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  1042. if(empty($oProfile))
  1043. return array();
  1044. $iProfileId = $oProfile->id();
  1045. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  1046. return $this->_getBlockPost($iProfileId, array(
  1047. 'type' => $sType,
  1048. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  1049. ));
  1050. }
  1051. /**
  1052. * @page service Service Calls
  1053. * @section bx_timeline Timeline
  1054. * @subsection bx_timeline-page_blocks Page Blocks
  1055. * @subsubsection bx_timeline-get_block_post_home get_block_post_home
  1056. *
  1057. * @code bx_srv('bx_timeline', 'get_block_post_home', [...]); @endcode
  1058. *
  1059. * Get Post block for site's Home page.
  1060. *
  1061. * @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.
  1062. *
  1063. * @see BxTimelineModule::serviceGetBlockPostHome
  1064. */
  1065. /**
  1066. * @ref bx_timeline-get_block_post_home "get_block_post_home"
  1067. */
  1068. public function serviceGetBlockPostHome()
  1069. {
  1070. $iProfileId = 0;
  1071. $sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  1072. return $this->_getBlockPost($iProfileId, array(
  1073. 'type' => $sType,
  1074. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  1075. ));
  1076. }
  1077. /**
  1078. * @page service Service Calls
  1079. * @section bx_timeline Timeline
  1080. * @subsection bx_timeline-page_blocks Page Blocks
  1081. * @subsubsection bx_timeline-get_block_post_account get_block_post_account
  1082. *
  1083. * @code bx_srv('bx_timeline', 'get_block_post_account', [...]); @endcode
  1084. *
  1085. * Get Post block for the Dashboard page.
  1086. *
  1087. * @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.
  1088. *
  1089. * @see BxTimelineModule::serviceGetBlockPostAccount
  1090. */
  1091. /**
  1092. * @ref bx_timeline-get_block_post_account "get_block_post_account"
  1093. */
  1094. public function serviceGetBlockPostAccount()
  1095. {
  1096. if(!isLogged())
  1097. return '';
  1098. $iProfileId = $this->getProfileId();
  1099. $sType = BX_TIMELINE_TYPE_FEED;
  1100. return $this->_getBlockPost($iProfileId, array(
  1101. 'type' => $sType,
  1102. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  1103. ));
  1104. }
  1105. /**
  1106. * @page service Service Calls
  1107. * @section bx_timeline Timeline
  1108. * @subsection bx_timeline-page_blocks Page Blocks
  1109. * @subsubsection bx_timeline-get_block_view get_block_view
  1110. *
  1111. * @code bx_srv('bx_timeline', 'get_block_view', [...]); @endcode
  1112. *
  1113. * Get Timeline View block for a separate page.
  1114. *
  1115. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  1116. * @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.
  1117. *
  1118. * @see BxTimelineModule::serviceGetBlockView
  1119. */
  1120. /**
  1121. * @ref bx_timeline-get_block_view "get_block_view"
  1122. */
  1123. public function serviceGetBlockView($iProfileId = 0)
  1124. {
  1125. return $this->_serviceGetBlockView($iProfileId, array(
  1126. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1127. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  1128. 'start' => -1,
  1129. 'per_page' => -1,
  1130. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  1131. 'timeline' => -1,
  1132. 'filter' => '',
  1133. 'modules' => array()
  1134. ));
  1135. }
  1136. /**
  1137. * @page service Service Calls
  1138. * @section bx_timeline Timeline
  1139. * @subsection bx_timeline-page_blocks Page Blocks
  1140. * @subsubsection bx_timeline-get_block_view_outline get_block_view_outline
  1141. *
  1142. * @code bx_srv('bx_timeline', 'get_block_view_outline', [...]); @endcode
  1143. *
  1144. * Get Outline View block for a separate page.
  1145. *
  1146. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  1147. * @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.
  1148. *
  1149. * @see BxTimelineModule::serviceGetBlockViewOutline
  1150. */
  1151. /**
  1152. * @ref bx_timeline-get_block_view_outline "get_block_view_outline"
  1153. */
  1154. public function serviceGetBlockViewOutline($iProfileId = 0)
  1155. {
  1156. return $this->_serviceGetBlockView($iProfileId, array(
  1157. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1158. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  1159. 'start' => -1,
  1160. 'per_page' => -1,
  1161. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  1162. 'timeline' => -1,
  1163. 'filter' => '',
  1164. 'modules' => array()
  1165. ));
  1166. }
  1167. /**
  1168. * @page service Service Calls
  1169. * @section bx_timeline Timeline
  1170. * @subsection bx_timeline-page_blocks Page Blocks
  1171. * @subsubsection bx_timeline-get_block_view_profile get_block_view_profile
  1172. *
  1173. * @code bx_srv('bx_timeline', 'get_block_view_profile', [...]); @endcode
  1174. *
  1175. * Get Timeline View block for the Profile page.
  1176. *
  1177. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  1178. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  1179. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1180. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1181. * @param $sFilter (optional) string value with filter name.
  1182. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1183. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1184. * @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.
  1185. *
  1186. * @see BxTimelineModule::serviceGetBlockViewProfile
  1187. */
  1188. /**
  1189. * @ref bx_timeline-get_block_view_profile "get_block_view_profile"
  1190. */
  1191. public function serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  1192. {
  1193. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, array(
  1194. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1195. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  1196. 'start' => $iStart,
  1197. 'per_page' => $iPerPage,
  1198. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  1199. 'timeline' => $iTimeline,
  1200. 'filter' => $sFilter,
  1201. 'modules' => $aModules
  1202. ));
  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_view_profile_outline get_block_view_profile_outline
  1209. *
  1210. * @code bx_srv('bx_timeline', 'get_block_view_profile_outline', [...]); @endcode
  1211. *
  1212. * Get Outline View block for the Profile page.
  1213. *
  1214. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  1215. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  1216. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1217. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1218. * @param $sFilter (optional) string value with filter name.
  1219. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1220. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1221. * @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.
  1222. *
  1223. * @see BxTimelineModule::serviceGetBlockViewProfileOutline
  1224. */
  1225. /**
  1226. * @ref bx_timeline-get_block_view_profile_outline "get_block_view_profile_outline"
  1227. */
  1228. public function serviceGetBlockViewProfileOutline($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  1229. {
  1230. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, array(
  1231. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1232. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  1233. 'start' => $iStart,
  1234. 'per_page' => $iPerPage,
  1235. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  1236. 'timeline' => $iTimeline,
  1237. 'filter' => $sFilter,
  1238. 'modules' => $aModules
  1239. ));
  1240. }
  1241. public function serviceGetBlockViewsCustom($aParams = array())
  1242. {
  1243. $aParams = array_merge(array(
  1244. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1245. 'type' => BX_BASE_MOD_NTFS_TYPE_PUBLIC,
  1246. 'owner_id' => 0,
  1247. ), $aParams);
  1248. return $this->_serviceGetBlockViews($aParams);
  1249. }
  1250. public function serviceGetBlockViewsTimeline($sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC, $iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1251. {
  1252. return $this->_serviceGetBlockViews(array(
  1253. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1254. 'type' => $sType,
  1255. 'owner_id' => $iProfileId,
  1256. 'start' => $iStart,
  1257. 'per_page' => $iPerPage,
  1258. 'per_page_default' => $this->_oConfig->getPerPage(),
  1259. 'timeline' => $iTimeline,
  1260. 'filter' => $sFilter,
  1261. 'modules' => $aModules
  1262. ));
  1263. }
  1264. public function serviceGetBlockViewsOutline($sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC, $iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1265. {
  1266. return $this->_serviceGetBlockViews(array(
  1267. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1268. 'type' => $sType,
  1269. 'owner_id' => $iProfileId,
  1270. 'start' => $iStart,
  1271. 'per_page' => $iPerPage,
  1272. 'per_page_default' => $this->_oConfig->getPerPage(),
  1273. 'timeline' => $iTimeline,
  1274. 'filter' => $sFilter,
  1275. 'modules' => $aModules
  1276. ));
  1277. }
  1278. /**
  1279. * @page service Service Calls
  1280. * @section bx_timeline Timeline
  1281. * @subsection bx_timeline-page_blocks Page Blocks
  1282. * @subsubsection bx_timeline-get_block_view_home get_block_view_home
  1283. *
  1284. * @code bx_srv('bx_timeline', 'get_block_view_home', [...]); @endcode
  1285. *
  1286. * Get Timeline View block for site's Home page.
  1287. *
  1288. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1289. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1290. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1291. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1292. * @param $sFilter (optional) string value with filter name.
  1293. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1294. * @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.
  1295. *
  1296. * @see BxTimelineModule::serviceGetBlockViewHome
  1297. */
  1298. /**
  1299. * @ref bx_timeline-get_block_view_home "get_block_view_home"
  1300. */
  1301. public function serviceGetBlockViewHome($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1302. {
  1303. return $this->_serviceGetBlockViewHome(array(
  1304. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1305. 'type' => BX_BASE_MOD_NTFS_TYPE_PUBLIC,
  1306. 'owner_id' => $iProfileId,
  1307. 'start' => $iStart,
  1308. 'per_page' => $iPerPage,
  1309. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  1310. 'timeline' => $iTimeline,
  1311. 'filter' => $sFilter,
  1312. 'modules' => $aModules
  1313. ));
  1314. }
  1315. /**
  1316. * @page service Service Calls
  1317. * @section bx_timeline Timeline
  1318. * @subsection bx_timeline-page_blocks Page Blocks
  1319. * @subsubsection bx_timeline-get_block_view_home_outline get_block_view_home_outline
  1320. *
  1321. * @code bx_srv('bx_timeline', 'get_block_view_home_outline', [...]); @endcode
  1322. *
  1323. * Get Outline View block for site's Home page.
  1324. *
  1325. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1326. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1327. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1328. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1329. * @param $sFilter (optional) string value with filter name.
  1330. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1331. * @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.
  1332. *
  1333. * @see BxTimelineModule::serviceGetBlockViewHomeOutline
  1334. */
  1335. /**
  1336. * @ref bx_timeline-get_block_view_home_outline "get_block_view_home_outline"
  1337. */
  1338. public function serviceGetBlockViewHomeOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1339. {
  1340. return $this->_serviceGetBlockViewHome(array(
  1341. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1342. 'type' => BX_BASE_MOD_NTFS_TYPE_PUBLIC,
  1343. 'owner_id' => $iProfileId,
  1344. 'start' => $iStart,
  1345. 'per_page' => $iPerPage,
  1346. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  1347. 'timeline' => $iTimeline,
  1348. 'filter' => $sFilter,
  1349. 'modules' => $aModules
  1350. ));
  1351. }
  1352. /**
  1353. * @page service Service Calls
  1354. * @section bx_timeline Timeline
  1355. * @subsection bx_timeline-page_blocks Page Blocks
  1356. * @subsubsection bx_timeline-get_block_view_hot get_block_view_hot
  1357. *
  1358. * @code bx_srv('bx_timeline', 'get_block_view_hot', [...]); @endcode
  1359. *
  1360. * Get Timeline View block with Hot public events.
  1361. *
  1362. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1363. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1364. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1365. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1366. * @param $sFilter (optional) string value with filter name.
  1367. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1368. * @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.
  1369. *
  1370. * @see BxTimelineModule::serviceGetBlockViewHot
  1371. */
  1372. /**
  1373. * @ref bx_timeline-get_block_view_hot "get_block_view_hot"
  1374. */
  1375. public function serviceGetBlockViewHot($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1376. {
  1377. return $this->_serviceGetBlockViewHot(array(
  1378. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1379. 'type' => BX_TIMELINE_TYPE_HOT,
  1380. 'owner_id' => $iProfileId,
  1381. 'start' => $iStart,
  1382. 'per_page' => $iPerPage,
  1383. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  1384. 'timeline' => $iTimeline,
  1385. 'filter' => $sFilter,
  1386. 'modules' => $aModules
  1387. ));
  1388. }
  1389. /**
  1390. * @page service Service Calls
  1391. * @section bx_timeline Timeline
  1392. * @subsection bx_timeline-page_blocks Page Blocks
  1393. * @subsubsection bx_timeline-get_block_view_hot_outline get_block_view_hot_outline
  1394. *
  1395. * @code bx_srv('bx_timeline', 'get_block_view_hot_outline', [...]); @endcode
  1396. *
  1397. * Get Outline View block with Hot public events.
  1398. *
  1399. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1400. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1401. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1402. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1403. * @param $sFilter (optional) string value with filter name.
  1404. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1405. * @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.
  1406. *
  1407. * @see BxTimelineModule::serviceGetBlockViewHotOutline
  1408. */
  1409. /**
  1410. * @ref bx_timeline-get_block_view_hot_outline "get_block_view_hot_outline"
  1411. */
  1412. public function serviceGetBlockViewHotOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1413. {
  1414. return $this->_serviceGetBlockViewHot(array(
  1415. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1416. 'type' => BX_TIMELINE_TYPE_HOT,
  1417. 'owner_id' => $iProfileId,
  1418. 'start' => $iStart,
  1419. 'per_page' => $iPerPage,
  1420. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  1421. 'timeline' => $iTimeline,
  1422. 'filter' => $sFilter,
  1423. 'modules' => $aModules
  1424. ));
  1425. }
  1426. /**
  1427. * @page service Service Calls
  1428. * @section bx_timeline Timeline
  1429. * @subsection bx_timeline-page_blocks Page Blocks
  1430. * @subsubsection bx_timeline-get_block_view_account get_block_view_account
  1431. *
  1432. * @code bx_srv('bx_timeline', 'get_block_view_account', [...]); @endcode
  1433. *
  1434. * Get Timeline View block for the Dashboard page.
  1435. *
  1436. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1437. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1438. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1439. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1440. * @param $sFilter (optional) string value with filter name.
  1441. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1442. * @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.
  1443. *
  1444. * @see BxTimelineModule::serviceGetBlockViewAccount
  1445. */
  1446. /**
  1447. * @ref bx_timeline-get_block_view_account "get_block_view_account"
  1448. */
  1449. public function serviceGetBlockViewAccount($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1450. {
  1451. if(!isLogged())
  1452. return '';
  1453. return $this->_serviceGetBlockViewByType(array(
  1454. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1455. 'type' => BX_TIMELINE_TYPE_FEED,
  1456. 'owner_id' => $iProfileId,
  1457. 'start' => $iStart,
  1458. 'per_page' => $iPerPage,
  1459. 'per_page_default' => $this->_oConfig->getPerPage('account'),
  1460. 'timeline' => $iTimeline,
  1461. 'filter' => $sFilter,
  1462. 'modules' => $aModules
  1463. ));
  1464. }
  1465. /**
  1466. * @page service Service Calls
  1467. * @section bx_timeline Timeline
  1468. * @subsection bx_timeline-page_blocks Page Blocks
  1469. * @subsubsection bx_timeline-get_block_view_account_outline get_block_view_account_outline
  1470. *
  1471. * @code bx_srv('bx_timeline', 'get_block_view_account_outline', [...]); @endcode
  1472. *
  1473. * Get Outline View block for the Dashboard page.
  1474. *
  1475. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1476. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1477. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1478. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1479. * @param $sFilter (optional) string value with filter name.
  1480. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1481. * @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.
  1482. *
  1483. * @see BxTimelineModule::serviceGetBlockViewAccountOutline
  1484. */
  1485. /**
  1486. * @ref bx_timeline-get_block_view_account_outline "get_block_view_account_outline"
  1487. */
  1488. public function serviceGetBlockViewAccountOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1489. {
  1490. if(!isLogged())
  1491. return '';
  1492. return $this->_serviceGetBlockViewByType(array(
  1493. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1494. 'type' => BX_TIMELINE_TYPE_FEED,
  1495. 'owner_id' => $iProfileId,
  1496. 'start' => $iStart,
  1497. 'per_page' => $iPerPage,
  1498. 'per_page_default' => $this->_oConfig->getPerPage('account'),
  1499. 'timeline' => $iTimeline,
  1500. 'filter' => $sFilter,
  1501. 'modules' => $aModules
  1502. ));
  1503. }
  1504. /**
  1505. * @page service Service Calls
  1506. * @section bx_timeline Timeline
  1507. * @subsection bx_timeline-page_blocks Page Blocks
  1508. * @subsubsection bx_timeline-get_block_view_custom get_block_view_custom
  1509. *
  1510. * @code bx_srv('bx_timeline', 'get_block_view_custom', [...]); @endcode
  1511. *
  1512. * Get custom Timeline View block.
  1513. *
  1514. * @param $aParams (optional) an array with block parameneters.
  1515. * @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.
  1516. *
  1517. * @see BxTimelineModule::serviceGetBlockViewCustom
  1518. */
  1519. /**
  1520. * @ref bx_timeline-get_block_view_custom "get_block_view_custom"
  1521. */
  1522. public function serviceGetBlockViewCustom($aParams = array())
  1523. {
  1524. return $this->_serviceGetBlockViewByType($aParams);
  1525. }
  1526. public function serviceGetBlockMenuDb($aParams = array())
  1527. {
  1528. $aParams = $this->_prepareParams(array_merge($aParams, [
  1529. 'name' => BX_TIMELINE_NAME_VIEWS_DB,
  1530. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1531. 'type' => BX_TIMELINE_TYPE_FEED,
  1532. 'owner_id' => $this->getProfileId()
  1533. ]));
  1534. if(($sType = $this->_oConfig->getUserChoice('type')) !== false)
  1535. $aParams['type'] = $sType;
  1536. $sMenu = $this->_oConfig->getObject('menu_feeds');
  1537. $oMenu = BxDolMenu::getObjectInstance($sMenu);
  1538. $sSelectedModule = $this->getName();
  1539. $sSelectedName = $aParams['type'];
  1540. if(($aModule = $this->_oDb->getModuleByName($aParams['type']))) {
  1541. $sSelectedModule = $aModule['name'];
  1542. $sSelectedName = $aModule['uri'];
  1543. }
  1544. $oMenu->setSelected($sSelectedModule, $sSelectedName);
  1545. $oMenu->setBrowseParams($aParams);
  1546. return $oMenu->getCode();
  1547. }
  1548. public function serviceGetBlockViewsDb($aParams = [])
  1549. {
  1550. $aParams = $this->_prepareParams(array_merge($aParams, [
  1551. 'name' => BX_TIMELINE_NAME_VIEWS_DB,
  1552. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1553. 'type' => BX_TIMELINE_TYPE_FEED,
  1554. 'owner_id' => $this->getProfileId()
  1555. ]));
  1556. if(($sType = $this->_oConfig->getUserChoice('type')) !== false)
  1557. $aParams['type'] = $sType;
  1558. $this->_iOwnerId = $aParams['owner_id'];
  1559. return $this->_oTemplate->getViewsDbBlock($aParams);
  1560. }
  1561. /**
  1562. * @page service Service Calls
  1563. * @section bx_timeline Timeline
  1564. * @subsection bx_timeline-page_blocks Page Blocks
  1565. * @subsubsection bx_timeline-get_block_item get_block_item
  1566. *
  1567. * @code bx_srv('bx_timeline', 'get_block_item', [...]); @endcode
  1568. *
  1569. * Get View Item block.
  1570. *
  1571. * @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.
  1572. *
  1573. * @see BxTimelineModule::serviceGetBlockItem
  1574. */
  1575. /**
  1576. * @ref bx_timeline-get_block_item "get_block_item"
  1577. */
  1578. public function serviceGetBlockItem()
  1579. {
  1580. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1581. if(!$iItemId)
  1582. return array();
  1583. $aParams = $this->_prepareParams(array(
  1584. 'view' => BX_TIMELINE_VIEW_ITEM,
  1585. 'type' => BX_TIMELINE_TYPE_ITEM
  1586. ));
  1587. $aItemData = $this->getItemData($iItemId, $aParams);
  1588. return $this->_oTemplate->getItemBlock($aItemData, $aParams);
  1589. }
  1590. public function serviceGetBlockItemContent()
  1591. {
  1592. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1593. $sMode = bx_process_input(bx_get('mode'));
  1594. if(!$iItemId || !$sMode)
  1595. return '';
  1596. return $this->_oTemplate->getItemBlockContent($iItemId, $sMode);
  1597. }
  1598. public function serviceGetBlockItemInfo()
  1599. {
  1600. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1601. if(!$iItemId)
  1602. return '';
  1603. return $this->_oTemplate->getItemBlockInfo($iItemId);
  1604. }
  1605. public function serviceGetBlockItemComments()
  1606. {
  1607. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1608. if(!$iItemId)
  1609. return '';
  1610. return $this->_oTemplate->getItemBlockComments($iItemId);
  1611. }
  1612. public function serviceGetBlockMuted($iProfileId = 0)
  1613. {
  1614. if(!isLogged())
  1615. return MsgBox(_t('_Access denied'));
  1616. if($iProfileId == 0)
  1617. $iProfileId = $this->_iProfileId;
  1618. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getObject('grid_mute'));
  1619. if(!$oGrid)
  1620. return MsgBox('_Empty');
  1621. $oGrid->setProfile($iProfileId);
  1622. return $oGrid->getCode();
  1623. }
  1624. public function serviceGetPost($mixedEvent, $aParams = array())
  1625. {
  1626. if(!empty($mixedEvent) && !is_array($mixedEvent))
  1627. $mixedEvent = $this->_oDb->getContentInfoById((int)$mixedEvent);
  1628. if(empty($mixedEvent) || !is_array($mixedEvent))
  1629. return '';
  1630. $aParams = $this->_prepareParams(array_merge(array(
  1631. 'view' => BX_TIMELINE_VIEW_ITEM,
  1632. 'type' => BX_TIMELINE_TYPE_ITEM
  1633. ), $aParams));
  1634. return $this->_oTemplate->getPost($mixedEvent, $aParams);
  1635. }
  1636. public function serviceGetTimelineRepostAllowedView($aEvent)
  1637. {
  1638. return isset($aEvent['content']['allowed_view']) ? $aEvent['content']['allowed_view'] : CHECK_ACTION_RESULT_ALLOWED;
  1639. }
  1640. /**
  1641. * @page service Service Calls
  1642. * @section bx_timeline Timeline
  1643. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1644. * @subsubsection bx_timeline-get_notifications_data get_notifications_data
  1645. *
  1646. * @code bx_srv('bx_timeline', 'get_notifications_data', [...]); @endcode
  1647. *
  1648. * Data for Notifications module.
  1649. *
  1650. * @return an array with special format.
  1651. *
  1652. * @see BxTimelineModule::serviceGetNotificationsData
  1653. */
  1654. /**
  1655. * @ref bx_timeline-get_notifications_data "get_notifications_data"
  1656. */
  1657. public function serviceGetNotificationsData()
  1658. {
  1659. $sModule = $this->_aModule['name'];
  1660. return array(
  1661. 'handlers' => array(
  1662. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'post_common', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module'),
  1663. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete'),
  1664. array('group' => $sModule . '_object_publish_failed', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'publish_failed', 'module_name' => $sModule, 'module_method' => 'get_notifications_post_publish_failed', 'module_class' => 'Module'),
  1665. array('group' => $sModule . '_object_publish_succeeded', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'publish_succeeded', 'module_name' => $sModule, 'module_method' => 'get_notifications_post_publish_succeeded', 'module_class' => 'Module'),
  1666. array('group' => $sModule . '_repost', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'repost', 'module_name' => $sModule, 'module_method' => 'get_notifications_repost', 'module_class' => 'Module'),
  1667. array('group' => $sModule . '_repost', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete_repost'),
  1668. array('group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment', 'module_class' => 'Module'),
  1669. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  1670. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'),
  1671. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  1672. array('group' => $sModule . '_reaction', 'type' => 'insert', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_reaction', 'module_class' => 'Module'),
  1673. array('group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote'),
  1674. 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'),
  1675. 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'),
  1676. ),
  1677. 'settings' => array(
  1678. array('group' => 'content', 'unit' => $sModule, 'action' => 'post_common', 'types' => array('personal', 'follow_member', 'follow_context')),
  1679. array('group' => 'content', 'unit' => $sModule, 'action' => 'publish_failed', 'types' => array('personal')),
  1680. array('group' => 'content', 'unit' => $sModule, 'action' => 'publish_succeeded', 'types' => array('personal')),
  1681. array('group' => 'content', 'unit' => $sModule, 'action' => 'repost', 'types' => array('follow_member', 'follow_context')),
  1682. array('group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => array('personal', 'follow_member', 'follow_context')),
  1683. array('group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1684. array('group' => 'vote', 'unit' => $sModule . '_reactions', 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1685. array('group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => array('personal', 'follow_member', 'follow_context')),
  1686. array('group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => array('personal', 'follow_member', 'follow_context'))
  1687. ),
  1688. 'alerts' => array(
  1689. array('unit' => $sModule, 'action' => 'post_common'),
  1690. array('unit' => $sModule, 'action' => 'publish_failed'),
  1691. array('unit' => $sModule, 'action' => 'publish_succeeded'),
  1692. array('unit' => $sModule, 'action' => 'delete'),
  1693. array('unit' => $sModule, 'action' => 'repost'),
  1694. array('unit' => $sModule, 'action' => 'delete_repost'),
  1695. array('unit' => $sModule, 'action' => 'commentPost'),
  1696. array('unit' => $sModule, 'action' => 'commentRemoved'),
  1697. array('unit' => $sModule, 'action' => 'doVote'),
  1698. array('unit' => $sModule, 'action' => 'undoVote'),
  1699. array('unit' => $sModule . '_reactions', 'action' => 'doVote'),
  1700. array('unit' => $sModule . '_reactions', 'action' => 'undoVote'),
  1701. array('unit' => $sModule, 'action' => 'doVoteUp'),
  1702. array('unit' => $sModule, 'action' => 'doVoteDown'),
  1703. )
  1704. );
  1705. }
  1706. /**
  1707. * @page service Service Calls
  1708. * @section bx_timeline Timeline
  1709. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1710. * @subsubsection bx_timeline-get_notifications_repost get_notifications_repost
  1711. *
  1712. * @code bx_srv('bx_timeline', 'get_notifications_repost', [...]); @endcode
  1713. *
  1714. * Get data for Repost event to display in Notifications module.
  1715. *
  1716. * @param $aEvent an array with event description.
  1717. * @return an array with special format.
  1718. *
  1719. * @see BxTimelineModule::serviceGetNotificationsRepost
  1720. */
  1721. /**
  1722. * @ref bx_timeline-get_notifications_repost "get_notifications_repost"
  1723. */
  1724. public function serviceGetNotificationsRepost($aEvent)
  1725. {
  1726. $aResult = $this->serviceGetNotificationsPost($aEvent);
  1727. $aResult['lang_key'] = '_bx_timeline_txt_object_reposted';
  1728. return $aResult;
  1729. }
  1730. /**
  1731. * @page service Service Calls
  1732. * @section bx_timeline Timeline
  1733. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1734. * @subsubsection bx_timeline-get_notifications_post get_notifications_post
  1735. *
  1736. * @code bx_srv('bx_timeline', 'get_notifications_post', [...]); @endcode
  1737. *
  1738. * Get data for Post event to display in Notifications module.
  1739. *
  1740. * @param $aEvent an array with event description.
  1741. * @return an array with special format.
  1742. *
  1743. * @see BxTimelineModule::serviceGetNotificationsPost
  1744. */
  1745. /**
  1746. * @ref bx_timeline-get_notifications_post "get_notifications_post"
  1747. */
  1748. public function serviceGetNotificationsPost($aEvent)
  1749. {
  1750. $CNF = &$this->_oConfig->CNF;
  1751. $iContent = (int)$aEvent['object_id'];
  1752. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1753. if(empty($aContent) || !is_array($aContent))
  1754. return array();
  1755. if($this->_oConfig->isSystem($aContent['type'], $aContent['action']))
  1756. $iEntryAuthor = (int)$aContent['owner_id'];
  1757. else
  1758. $iEntryAuthor = (int)$aContent['object_id'];
  1759. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1760. return array(
  1761. 'entry_sample' => $CNF['T']['txt_sample_single_ext'],
  1762. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1763. 'entry_caption' => $sEntryCaption,
  1764. 'entry_author' => $iEntryAuthor,
  1765. 'lang_key' => '' //may be empty or not specified. In this case the default one from Notification module will be used.
  1766. );
  1767. }
  1768. /**
  1769. * @page service Service Calls
  1770. * @section bx_timeline Timeline
  1771. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1772. * @subsubsection bx_timeline-get_notifications_comment get_notifications_comment
  1773. *
  1774. * @code bx_srv('bx_timeline', 'get_notifications_comment', [...]); @endcode
  1775. *
  1776. * Get data for Post Comment event to display in Notifications module.
  1777. *
  1778. * @param $aEvent an array with event description.
  1779. * @return an array with special format.
  1780. *
  1781. * @see BxTimelineModule::serviceGetNotificationsComment
  1782. */
  1783. /**
  1784. * @ref bx_timeline-get_notifications_comment "get_notifications_comment"
  1785. */
  1786. public function serviceGetNotificationsComment($aEvent)
  1787. {
  1788. $CNF = &$this->_oConfig->CNF;
  1789. $iContent = (int)$aEvent['object_id'];
  1790. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1791. if(empty($aContent) || !is_array($aContent))
  1792. return array();
  1793. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContent);
  1794. if(!$oComment || !$oComment->isEnabled())
  1795. return array();
  1796. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1797. return array(
  1798. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1799. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1800. 'entry_caption' => $sEntryCaption,
  1801. 'entry_author' => $aContent['owner_id'],
  1802. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  1803. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  1804. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1805. );
  1806. }
  1807. /**
  1808. * @page service Service Calls
  1809. * @section bx_timeline Timeline
  1810. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1811. * @subsubsection bx_timeline-get_notifications_vote get_notifications_vote
  1812. *
  1813. * @code bx_srv('bx_timeline', 'get_notifications_vote', [...]); @endcode
  1814. *
  1815. * Get data for Vote event to display in Notifications module.
  1816. *
  1817. * @param $aEvent an array with event description.
  1818. * @return an array with special format.
  1819. *
  1820. * @see BxTimelineModule::serviceGetNotificationsVote
  1821. */
  1822. /**
  1823. * @ref bx_timeline-get_notifications_vote "get_notifications_vote"
  1824. */
  1825. public function serviceGetNotificationsVote($aEvent)
  1826. {
  1827. $CNF = &$this->_oConfig->CNF;
  1828. $iContent = (int)$aEvent['object_id'];
  1829. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1830. if(empty($aContent) || !is_array($aContent))
  1831. return array();
  1832. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContent);
  1833. if(!$oVote || !$oVote->isEnabled())
  1834. return array();
  1835. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1836. return array(
  1837. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1838. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1839. 'entry_caption' => $sEntryCaption,
  1840. 'entry_author' => $aContent['owner_id'],
  1841. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  1842. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1843. );
  1844. }
  1845. /**
  1846. * Entry post vote for Notifications module
  1847. */
  1848. public function serviceGetNotificationsReaction($aEvent)
  1849. {
  1850. $CNF = &$this->_oConfig->CNF;
  1851. $iContent = (int)$aEvent['object_id'];
  1852. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1853. if(empty($aContent) || !is_array($aContent))
  1854. return array();
  1855. $oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $iContent);
  1856. if(!$oReaction || !$oReaction->isEnabled())
  1857. return array();
  1858. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  1859. if(empty($aSubentry) || !is_array($aSubentry))
  1860. return array();
  1861. $aSubentrySampleParams = array();
  1862. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  1863. if(!empty($aReaction['title']))
  1864. $aSubentrySampleParams[] = $aReaction['title'];
  1865. else
  1866. $aSubentrySampleParams[] = '_undefined';
  1867. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1868. return array(
  1869. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1870. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1871. 'entry_caption' => $sEntryCaption,
  1872. 'entry_author' => $aContent['owner_id'],
  1873. 'subentry_sample' => $CNF['T']['txt_sample_reaction_single'],
  1874. 'subentry_sample_params' => $aSubentrySampleParams,
  1875. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1876. );
  1877. }
  1878. /**
  1879. * @page service Service Calls
  1880. * @section bx_timeline Timeline
  1881. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1882. * @subsubsection bx_timeline-get_notifications_score_up get_notifications_score_up
  1883. *
  1884. * @code bx_srv('bx_timeline', 'get_notifications_score_up', [...]); @endcode
  1885. *
  1886. * Get data for Score Up Vote event to display in Notifications module.
  1887. *
  1888. * @param $aEvent an array with event description.
  1889. * @return an array with special format.
  1890. *
  1891. * @see BxTimelineModule::serviceGetNotificationsScoreUp
  1892. */
  1893. /**
  1894. * @ref bx_timeline-get_notifications_score_up "get_notifications_score_up"
  1895. */
  1896. public function serviceGetNotificationsScoreUp($aEvent)
  1897. {
  1898. return $this->_serviceGetNotificationsScore('up', $aEvent);
  1899. }
  1900. /**
  1901. * @page service Service Calls
  1902. * @section bx_timeline Timeline
  1903. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1904. * @subsubsection bx_timeline-get_notifications_score_down get_notifications_score_down
  1905. *
  1906. * @code bx_srv('bx_timeline', 'get_notifications_score_down', [...]); @endcode
  1907. *
  1908. * Get data for Score Down Vote event to display in Notifications module.
  1909. *
  1910. * @param $aEvent an array with event description.
  1911. * @return an array with special format.
  1912. *
  1913. * @see BxTimelineModule::serviceGetNotificationsScoreDown
  1914. */
  1915. /**
  1916. * @ref bx_timeline-get_notifications_score_down "get_notifications_score_down"
  1917. */
  1918. public function serviceGetNotificationsScoreDown($aEvent)
  1919. {
  1920. return $this->_serviceGetNotificationsScore('down', $aEvent);
  1921. }
  1922. protected function _serviceGetNotificationsScore($sType, $aEvent)
  1923. {
  1924. $CNF = &$this->_oConfig->CNF;
  1925. $iContent = (int)$aEvent['object_id'];
  1926. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1927. if(empty($aContent) || !is_array($aContent))
  1928. return array();
  1929. $oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContent);
  1930. if(!$oScore || !$oScore->isEnabled())
  1931. return array();
  1932. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1933. return array(
  1934. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1935. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1936. 'entry_caption' => $sEntryCaption,
  1937. 'entry_author' => $aContent['owner_id'],
  1938. 'subentry_sample' => $CNF['T']['txt_sample_score_' . $sType . '_single'],
  1939. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1940. );
  1941. }
  1942. /**
  1943. * @page service Service Calls
  1944. * @section bx_timeline Timeline
  1945. * @subsection bx_timeline-repost Repost
  1946. * @subsubsection bx_timeline-get_repost_element_block get_repost_element_block
  1947. *
  1948. * @code bx_srv('bx_timeline', 'get_repost_element_block', [...]); @endcode
  1949. *
  1950. * Get repost element for content based modules.
  1951. *
  1952. * @param $iOwnerId integer value with owner profile ID.
  1953. * @param $sType string value with type (module name).
  1954. * @param $sAction string value with action (module action).
  1955. * @param $iObjectId integer value with object ID to be reposted.
  1956. * @param $aParams (optional) an array with additional params.
  1957. * @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.
  1958. *
  1959. * @see BxTimelineModule::serviceGetRepostElementBlock
  1960. */
  1961. /**
  1962. * @ref bx_timeline-get_repost_element_block "get_repost_element_block"
  1963. */
  1964. public function serviceGetRepostElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
  1965. {
  1966. if(!$this->isEnabled())
  1967. return '';
  1968. $aParams = array_merge($this->_oConfig->getRepostDefaults(), $aParams);
  1969. return $this->_oTemplate->getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
  1970. }
  1971. /**
  1972. * @page service Service Calls
  1973. * @section bx_timeline Timeline
  1974. * @subsection bx_timeline-repost Repost
  1975. * @subsubsection bx_timeline-get_repost_counter get_repost_counter
  1976. *
  1977. * @code bx_srv('bx_timeline', 'get_repost_counter', [...]); @endcode
  1978. *
  1979. * Get repost counter.
  1980. *
  1981. * @param $sType string value with type (module name).
  1982. * @param $sAction string value with action (module action).
  1983. * @param $iObjectId integer value with object ID to be reposted.
  1984. * @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.
  1985. *
  1986. * @see BxTimelineModule::serviceGetRepostCounter
  1987. */
  1988. /**
  1989. * @ref bx_timeline-get_repost_counter "get_repost_counter"
  1990. */
  1991. public function serviceGetRepostCounter($sType, $sAction, $iObjectId)
  1992. {
  1993. if(!$this->isEnabled())
  1994. return '';
  1995. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1996. return $this->_oTemplate->getRepostCounter($aReposted);
  1997. }
  1998. /**
  1999. * @page service Service Calls
  2000. * @section bx_timeline Timeline
  2001. * @subsection bx_timeline-repost Repost
  2002. * @subsubsection bx_timeline-get_repost_js_script get_repost_js_script
  2003. *
  2004. * @code bx_srv('bx_timeline', 'get_repost_js_script', [...]); @endcode
  2005. *
  2006. * Get repost JavaScript code.
  2007. *
  2008. * @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.
  2009. *
  2010. * @see BxTimelineModule::serviceGetRepostJsScript
  2011. */
  2012. /**
  2013. * @ref bx_timeline-get_repost_js_script "get_repost_js_script"
  2014. */
  2015. public function serviceGetRepostJsScript()
  2016. {
  2017. if(!$this->isEnabled())
  2018. return '';
  2019. return $this->_oTemplate->getRepostJsScript();
  2020. }
  2021. /**
  2022. * @page service Service Calls
  2023. * @section bx_timeline Timeline
  2024. * @subsection bx_timeline-repost Repost
  2025. * @subsubsection bx_timeline-get_repost_js_click get_repost_js_click
  2026. *
  2027. * @code bx_srv('bx_timeline', 'get_repost_js_click', [...]); @endcode
  2028. *
  2029. * Get repost JavaScript code for OnClick event.
  2030. *
  2031. * @param $iOwnerId integer value with owner profile ID.
  2032. * @param $sType string value with type (module name).
  2033. * @param $sAction string value with action (module action).
  2034. * @param $iObjectId integer value with object ID to be reposted.
  2035. * @return HTML string with JavaScript code to display in OnClick events of HTML elements.
  2036. *
  2037. * @see BxTimelineModule::serviceGetRepostJsClick
  2038. */
  2039. /**
  2040. * @ref bx_timeline-get_repost_js_click "get_repost_js_click"
  2041. */
  2042. public function serviceGetRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  2043. {
  2044. if(!$this->isEnabled())
  2045. return '';
  2046. return $this->_oTemplate->getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  2047. }
  2048. /**
  2049. * @page service Service Calls
  2050. * @section bx_timeline Timeline
  2051. * @subsection bx_timeline-repost Repost
  2052. * @subsubsection bx_timeline-get_repost_to_js_click get_repost_to_js_click
  2053. *
  2054. * @code bx_srv('bx_timeline', 'get_repost_to_js_click', [...]); @endcode
  2055. *
  2056. * Get 'repost to' JavaScript code for OnClick event.
  2057. *
  2058. * @param $iReposterId integer value with reposter profile ID.
  2059. * @param $sType string value with type (module name).
  2060. * @param $sAction string value with action (module action).
  2061. * @param $iObjectId integer value with object ID to be reposted.
  2062. * @return HTML string with JavaScript code to display in OnClick events of HTML elements.
  2063. *
  2064. * @see BxTimelineModule::serviceGetRepostToJsClick
  2065. */
  2066. /**
  2067. * @ref bx_timeline-get_repost_to_js_click "get_repost_to_js_click"
  2068. */
  2069. public function serviceGetRepostToJsClick($iReposterId, $sType, $sAction, $iObjectId)
  2070. {
  2071. if(!$this->isEnabled())
  2072. return '';
  2073. return $this->_oTemplate->getRepostToJsClick($iReposterId, $sType, $sAction, $iObjectId);
  2074. }
  2075. /**
  2076. * @page service Service Calls
  2077. * @section bx_timeline Timeline
  2078. * @subsection bx_timeline-repost Repost
  2079. * @subsubsection bx_timeline-repost repost
  2080. *
  2081. * @code bx_srv('bx_timeline', 'repost', [...]); @endcode
  2082. *
  2083. * Perform repost action.
  2084. *
  2085. * @param $iAuthorId integer value with performer profile ID.
  2086. * @param $iOwnerId integer value with repost event owner profile ID.
  2087. * @param $sType string value with type (module name).
  2088. * @param $sAction string value with action (module action).
  2089. * @param $iObjectId integer value with object ID to be reposted.
  2090. * @parem $bForce boolean value force reposting without ACL check.
  2091. * @return an array with error (code and message) or integer with newly created repost event ID.
  2092. *
  2093. * @see BxTimelineModule::serviceRepost
  2094. */
  2095. /**
  2096. * @ref bx_timeline-repost "repost"
  2097. */
  2098. public function serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $bForce = false)
  2099. {
  2100. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  2101. if(empty($aReposted) || !is_array($aReposted))
  2102. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  2103. $mixedAllowed = $this->isAllowedRepost($aReposted, true);
  2104. if(!$bForce && $mixedAllowed !== true)
  2105. return array('code' => 2, 'message' => strip_tags($mixedAllowed));
  2106. $bReposted = $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $iAuthorId);
  2107. if($bReposted)
  2108. return array('code' => 3, 'message' => _t('_bx_timeline_txt_err_already_reposted'));
  2109. $iId = $this->_oDb->insertEvent(array(
  2110. 'owner_id' => $iOwnerId,
  2111. 'system' => 0,
  2112. 'type' => $this->_oConfig->getPrefix('common_post') . 'repost',
  2113. 'action' => '',
  2114. 'object_id' => $iAuthorId,
  2115. 'object_owner_id' => $iAuthorId,
  2116. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault('object'),
  2117. 'content' => serialize(array(
  2118. 'type' => $sType,
  2119. 'action' => $sAction,
  2120. 'object_id' => $iObjectId,
  2121. )),
  2122. 'title' => '',
  2123. 'description' => ''
  2124. ));
  2125. if(empty($iId))
  2126. return array('code' => 4, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  2127. $this->onRepost($iId, $aReposted);
  2128. return $iId;
  2129. }
  2130. /**
  2131. * @page service Service Calls
  2132. * @section bx_timeline Timeline
  2133. * @subsection bx_timeline-repost Repost
  2134. * @subsubsection bx_timeline-repost_by_id repost_by_id
  2135. *
  2136. * @code bx_srv('bx_timeline', 'repost_by_id', [...]); @endcode
  2137. *
  2138. * Perform repost action by Timeline event ID.
  2139. *
  2140. * @param $iAuthorId integer value with performer profile ID.
  2141. * @param $iOwnerId integer value with repost event owner profile ID.
  2142. * @param $iEventId integer value with event ID which will be reposted.
  2143. * @parem $bForce boolean value force reposting without ACL check.
  2144. * @return an array with error (code and message) or integer with newly created repost event ID.
  2145. *
  2146. * @see BxTimelineModule::serviceRepostById
  2147. */
  2148. /**
  2149. * @ref bx_timeline-repost_by_id "repost_by_id"
  2150. */
  2151. public function serviceRepostById($iAuthorId, $iOwnerId, $iEventId, $bForce = false)
  2152. {
  2153. $aEvent = $this->_oDb->getEntriesBy(array('type' => 'id', 'id' => $iEventId));
  2154. if(empty($aEvent) || !is_array($aEvent))
  2155. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  2156. $sType = $aEvent['type'];
  2157. $sAction = $aEvent['action'];
  2158. $iObjectId = $this->_oConfig->isSystem($sType, $sAction) ? $aEvent['object_id'] : $aEvent['id'];
  2159. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  2160. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  2161. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  2162. if(empty($aReposted) || !is_array($aReposted))
  2163. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  2164. $aRepostedData = unserialize($aEvent['content']);
  2165. $sType = $aRepostedData['type'];
  2166. $sAction = $aRepostedData['action'];
  2167. $iObjectId = $aRepostedData['object_id'];
  2168. }
  2169. return $this->serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $bForce);
  2170. }
  2171. /**
  2172. * @page service Service Calls
  2173. * @section bx_timeline Timeline
  2174. * @subsection bx_timeline-other Other
  2175. * @subsubsection bx_timeline-update update
  2176. *
  2177. * @code bx_srv('bx_timeline', 'update', [...]); @endcode
  2178. *
  2179. * Update timeline event by ID.
  2180. *
  2181. * @param $iEventId integer value with event ID.
  2182. * @param $aSet an array with key=>value pairs for fields which should be updated.
  2183. * @return boolean value with the result of operation.
  2184. *
  2185. * @see BxTimelineModule::serviceUpdate
  2186. */
  2187. /**
  2188. * @ref bx_timeline-update "update"
  2189. */
  2190. public function serviceUpdate($iEventId, $aSet)
  2191. {
  2192. if(empty($iEventId))
  2193. return false;
  2194. return (int)$this->_oDb->updateEvent($aSet, array('id' => $iEventId)) > 0;
  2195. }
  2196. /**
  2197. * @page service Service Calls
  2198. * @section bx_timeline Timeline
  2199. * @subsection bx_timeline-other Other
  2200. * @subsubsection bx_timeline-get_menu_item_addon_comment get_menu_item_addon_comment
  2201. *
  2202. * @code bx_srv('bx_timeline', 'get_menu_item_addon_comment', [...]); @endcode
  2203. *
  2204. * Get addon for Comment menu item.
  2205. * NOTE. The service isn't used for now because comment functionality in card was updated.
  2206. *
  2207. * @param $sSystem string value with comments engine system.
  2208. * @param $iObjectId integer value with object ID.
  2209. * @return HTML string to display in menu item.
  2210. *
  2211. * @see BxTimelineModule::serviceGetMenuItemAddonComment
  2212. */
  2213. /**
  2214. * @ref bx_timeline-get_menu_item_addon_comment "get_menu_item_addon_comment"
  2215. */
  2216. public function serviceGetMenuItemAddonComment($sSystem, $iObjectId, $aBrowseParams = array())
  2217. {
  2218. if(empty($sSystem) || empty($iObjectId))
  2219. return '';
  2220. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  2221. if($oCmts === false)
  2222. return '';
  2223. $iCounter = (int)$oCmts->getCommentsCount();
  2224. if(empty($iCounter))
  2225. return '';
  2226. return $this->_oTemplate->parseLink('javascript:void(0)', $iCounter, array(
  2227. 'class' => 'bx-menu-item-addon',
  2228. 'title' => _t('_bx_timeline_menu_item_title_item_comment'),
  2229. 'onclick' => "javascript:" . $this->_oConfig->getJsObjectView($aBrowseParams) . ".commentItem(this, '" . $sSystem . "', " . $iObjectId . ")"
  2230. ));
  2231. }
  2232. /**
  2233. * @page service Service Calls
  2234. * @section bx_timeline Timeline
  2235. * @subsection bx_timeline-other Other
  2236. * @subsubsection bx_timeline-get_settings_checker_helper get_settings_checker_helper
  2237. *
  2238. * @code bx_srv('bx_timeline', 'get_settings_checker_helper', [...]); @endcode
  2239. *
  2240. * Get Checker Helper class name for Forms engine.
  2241. *
  2242. * @return string with Checker Helper class name.
  2243. *
  2244. * @see BxTimelineModule::serviceGetSettingsCheckerHelper
  2245. */
  2246. /**
  2247. * @ref bx_timeline-get_settings_checker_helper "get_settings_checker_helper"
  2248. */
  2249. public function serviceGetSettingsCheckerHelper()
  2250. {
  2251. bx_import('FormCheckerHelper', $this->_aModule);
  2252. return 'BxTimelineFormCheckerHelper';
  2253. }
  2254. /**
  2255. * @page service Service Calls
  2256. * @section bx_timeline Timeline
  2257. * @subsection bx_timeline-other Other
  2258. * @subsubsection bx_timeline-get_options_videos_preload get_options_videos_preload
  2259. *
  2260. * @code bx_srv('bx_timeline', 'get_options_videos_preload', [...]); @endcode
  2261. *
  2262. * Get an array with available options for 'Videos preload in Timeline' setting.
  2263. *
  2264. * @return an array with available options represented as key => value pairs.
  2265. *
  2266. * @see BxTimelineModule::serviceGetOptionsVideosPreload
  2267. */
  2268. /**
  2269. * @ref bx_timeline-get_options_videos_preload "get_options_videos_preload"
  2270. */
  2271. public function serviceGetOptionsVideosPreload()
  2272. {
  2273. $CNF = &$this->_oConfig->CNF;
  2274. $aOptions = array('auto', 'metadata', 'none');
  2275. $aResult = array();
  2276. foreach($aOptions as $sOption)
  2277. $aResult[] = array(
  2278. 'key' => $sOption,
  2279. 'value' => _t($CNF['T']['option_vp_' . $sOption])
  2280. );
  2281. return $aResult;
  2282. }
  2283. /**
  2284. * @page service Service Calls
  2285. * @section bx_timeline Timeline
  2286. * @subsection bx_timeline-other Other
  2287. * @subsubsection bx_timeline-get_options_videos_autoplay get_options_videos_autoplay
  2288. *
  2289. * @code bx_srv('bx_timeline', 'get_options_videos_autoplay', [...]); @endcode
  2290. *
  2291. * Get an array with available options for 'Videos autoplay in Timeline' setting.
  2292. *
  2293. * @return an array with available options represented as key => value pairs.
  2294. *
  2295. * @see BxTimelineModule::serviceGetOptionsVideosAutoplay
  2296. */
  2297. /**
  2298. * @ref bx_timeline-get_options_videos_autoplay "get_options_videos_autoplay"
  2299. */
  2300. public function serviceGetOptionsVideosAutoplay()
  2301. {
  2302. $CNF = &$this->_oConfig->CNF;
  2303. $aOptions = array(BX_TIMELINE_VAP_OFF, BX_TIMELINE_VAP_ON_MUTE, BX_TIMELINE_VAP_ON);
  2304. $aResult = array();
  2305. foreach($aOptions as $sOption)
  2306. $aResult[] = array(
  2307. 'key' => $sOption,
  2308. 'value' => _t($CNF['T']['option_vap_' . $sOption])
  2309. );
  2310. return $aResult;
  2311. }
  2312. /**
  2313. * @page service Service Calls
  2314. * @section bx_timeline Timeline
  2315. * @subsection bx_timeline-other Other
  2316. * @subsubsection bx_timeline-get_options_attachments_layout get_options_attachments_layout
  2317. *
  2318. * @code bx_srv('bx_timeline', 'get_options_attachments_layout', [...]); @endcode
  2319. *
  2320. * Get an array with available options for 'Show attachments as' setting.
  2321. *
  2322. * @return an array with available options represented as key => value pairs.
  2323. *
  2324. * @see BxTimelineModule::serviceGetOptionsAttachmentsLayout
  2325. */
  2326. /**
  2327. * @ref bx_timeline-get_options_attachments_layout "get_options_attachments_layout"
  2328. */
  2329. public function serviceGetOptionsAttachmentsLayout()
  2330. {
  2331. $CNF = &$this->_oConfig->CNF;
  2332. $aOptions = array(BX_TIMELINE_ML_GALLERY, BX_TIMELINE_ML_SHOWCASE);
  2333. $aResult = array();
  2334. foreach($aOptions as $sOption)
  2335. $aResult[] = array(
  2336. 'key' => $sOption,
  2337. 'value' => _t($CNF['T']['option_al_' . $sOption])
  2338. );
  2339. return $aResult;
  2340. }
  2341. /**
  2342. * @page service Service Calls
  2343. * @section bx_timeline Timeline
  2344. * @subsection bx_timeline-other Other
  2345. * @subsubsection bx_timeline-get_live_update get_live_update
  2346. *
  2347. * @code bx_srv('bx_timeline', 'get_live_update', [...]); @endcode
  2348. *
  2349. * Get an array with actual Live Update info. Only one live update notification for all new events.
  2350. *
  2351. * @return an array with Live Update info.
  2352. *
  2353. * @see BxTimelineModule::serviceGetLiveUpdate
  2354. */
  2355. /**
  2356. * @ref bx_timeline-get_live_update "get_live_update"
  2357. */
  2358. public function serviceGetLiveUpdate($aBrowseParams, $iProfileId, $iValue = 0, $iInit = 0)
  2359. {
  2360. $CNF = &$this->_oConfig->CNF;
  2361. $sKey = $this->_oConfig->getLiveUpdateKey($aBrowseParams);
  2362. bx_import('BxDolSession');
  2363. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  2364. return false;
  2365. $aParams = $this->_prepareParams($aBrowseParams);
  2366. $aParams = array_merge($aParams, array(
  2367. 'filter' => BX_TIMELINE_FILTER_OTHER_VIEWER
  2368. ));
  2369. $aEvents = $this->_oDb->getEvents($aParams);
  2370. if(empty($aEvents) || !is_array($aEvents))
  2371. return false;
  2372. $iValueNew = 0;
  2373. foreach($aEvents as $aEvent) {
  2374. if((int)$aEvent[$CNF['FIELD_STICKED']] != 0)
  2375. continue;
  2376. $sContent = $this->_oTemplate->getPost($aEvent, $aParams);
  2377. if(empty($sContent))
  2378. continue;
  2379. $iValueNew = $aEvent['id'];
  2380. break;
  2381. }
  2382. if($iValueNew == $iValue)
  2383. return false;
  2384. if((int)$iInit != 0)
  2385. return array('count' => $iValueNew);
  2386. return array(
  2387. 'count' => $iValueNew, // required (for initialization and visualization)
  2388. 'method' => $this->_oConfig->getJsObjectView($aBrowseParams) . '.showLiveUpdate(oData)', // required (for visualization)
  2389. 'data' => array(
  2390. 'code' => $this->_oTemplate->getLiveUpdate($aBrowseParams, $iProfileId, $iValue, $iValueNew)
  2391. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  2392. );
  2393. }
  2394. /**
  2395. * @page service Service Calls
  2396. * @section bx_timeline Timeline
  2397. * @subsection bx_timeline-other Other
  2398. * @subsubsection bx_timeline-get_live_updates get_live_updates
  2399. *
  2400. * @code bx_srv('bx_timeline', 'get_live_updates', [...]); @endcode
  2401. *
  2402. * Get an array with actual Live Update info. Separate live update notification for each new Event.
  2403. * Note. This method isn't used for now. @see BxTimelineModule::serviceGetLiveUpdate method instead.
  2404. *
  2405. * Note. This way to display live update notifications isn't used for now.
  2406. * See BxTimelineModule::serviceGetLiveUpdate method instead.
  2407. *
  2408. * @return an array with Live Update info.
  2409. *
  2410. * @see BxTimelineModule::serviceGetLiveUpdates
  2411. */
  2412. /**
  2413. * @ref bx_timeline-get_live_updates "get_live_updates"
  2414. */
  2415. public function serviceGetLiveUpdates($aBrowseParams, $iProfileId, $iCount = 0, $iInit = 0)
  2416. {
  2417. $sKey = $this->_oConfig->getLiveUpdateKey($aBrowseParams);
  2418. bx_import('BxDolSession');
  2419. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  2420. return false;
  2421. $aParams = $this->_prepareParams($aBrowseParams);
  2422. $aParams['filter'] = BX_TIMELINE_FILTER_OTHER_VIEWER;
  2423. $aParams['count'] = true;
  2424. $iCountNew = $this->_oDb->getEvents($aParams);
  2425. if($iCountNew == $iCount)
  2426. return false;
  2427. if((int)$iInit != 0)
  2428. return array('count' => $iCountNew);
  2429. return array(
  2430. 'count' => $iCountNew, // required (for initialization and visualization)
  2431. 'method' => $this->_oConfig->getJsObjectView($aBrowseParams) . '.showLiveUpdates(oData)', // required (for visualization)
  2432. 'data' => array(
  2433. 'code' => $this->_oTemplate->getLiveUpdates($aBrowseParams, $iProfileId, $iCount, $iCountNew)
  2434. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  2435. );
  2436. }
  2437. /**
  2438. * @page service Service Calls
  2439. * @section bx_timeline Accounts
  2440. * @subsection bx_timeline-other Other
  2441. * @subsubsection bx_timeline-get_menu_addon_manage_tools get_menu_addon_manage_tools
  2442. *
  2443. * @code bx_srv('bx_timeline', 'get_menu_addon_manage_tools', [...]); @endcode
  2444. *
  2445. * Get number of 'hidden' events for User End -> Dasboard page -> Manage block.
  2446. *
  2447. * @return integer number of 'hidden' events
  2448. *
  2449. * @see BxTimelineModule::serviceGetMenuAddonManageTools
  2450. */
  2451. /**
  2452. * @ref bx_timeline-get_menu_addon_manage_tools "get_menu_addon_manage_tools"
  2453. */
  2454. public function serviceGetMenuAddonManageTools()
  2455. {
  2456. $CNF = &$this->_oConfig->CNF;
  2457. bx_import('SearchResult', $this->_aModule);
  2458. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  2459. $oSearch = new $sClass();
  2460. $oSearch->unsetPaginate();
  2461. $oSearch->fillFilters(array('status' => BX_TIMELINE_STATUS_HIDDEN));
  2462. $iNum1 = $oSearch->getNum();
  2463. $oSearch->fillFilters(array('status' => ''));
  2464. $oSearch->fillFiltersByObjects(array('reported' => array('value' => '0', 'field' => 'reports', 'operator' => '>')));
  2465. $iNum2 = $oSearch->getNum();
  2466. return array(
  2467. 'counter1_value' => $iNum1,
  2468. 'counter2_value' => $iNum2,
  2469. 'counter3_value' => 0
  2470. );
  2471. }
  2472. /**
  2473. * @page service Service Calls
  2474. * @section bx_timeline Accounts
  2475. * @subsection bx_timeline-other Other
  2476. * @subsubsection bx_timeline-get_menu_addon_profile_stats get_menu_addon_profile_stats
  2477. *
  2478. * @code bx_srv('bx_timeline', 'get_menu_addon_profile_stats', [...]); @endcode
  2479. *
  2480. * Get number of 'muted' events for currently logged in user. User End -> Profile Stats.
  2481. *
  2482. * @return integer number of 'muted' events
  2483. *
  2484. * @see BxTimelineModule::serviceGetMenuAddonProfileStats
  2485. */
  2486. /**
  2487. * @ref bx_timeline-get_menu_addon_profile_stats "get_menu_addon_profile_stats"
  2488. */
  2489. public function serviceGetMenuAddonProfileStats($iProfileId = 0)
  2490. {
  2491. if(empty($iProfileId))
  2492. $iProfileId = $this->_iProfileId;
  2493. return $this->getConnectionMuteObject()->getConnectedContentCount($iProfileId);
  2494. }
  2495. public function serviceGet($aParams)
  2496. {
  2497. $aParams = $this->_prepareParams($aParams);
  2498. $aParams['return_data_type'] = 'array';
  2499. return $this->_oTemplate->getPosts($aParams);
  2500. }
  2501. public function serviceAdd($aValues)
  2502. {
  2503. return $this->getFormPost(array(
  2504. 'values' => $aValues
  2505. ));
  2506. }
  2507. public function serviceEdit($iId, $aValues)
  2508. {
  2509. return $this->getFormEdit($iId, array(
  2510. 'values' => $aValues
  2511. ));
  2512. }
  2513. /**
  2514. * Delete content entry
  2515. * @param $iContentId content id
  2516. * @return error message or empty string on success
  2517. */
  2518. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  2519. {
  2520. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2521. if(empty($aEvent) || !is_array($aEvent))
  2522. return _t('_Empty');
  2523. if(!$this->deleteEvent($aEvent))
  2524. return _t('_bx_timeline_txt_err_cannot_perform_action');
  2525. return '';
  2526. }
  2527. /*
  2528. * COMMON METHODS
  2529. */
  2530. public function getItemData($iId, $aParams = array())
  2531. {
  2532. $CNF = &$this->_oConfig->CNF;
  2533. if(empty($aParams))
  2534. $aParams = $this->_prepareParams(array(
  2535. 'view' => BX_TIMELINE_VIEW_ITEM,
  2536. 'type' => BX_TIMELINE_TYPE_ITEM
  2537. ));
  2538. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  2539. if(empty($aEvent))
  2540. return array('code' => 1, 'content' => _t('_Empty'));
  2541. $iProfile = (int)$aEvent[$CNF['FIELD_OWNER_ID']];
  2542. if(!empty($iProfile)) {
  2543. $oProfile = BxDolProfile::getInstance($iProfile);
  2544. if(!$oProfile)
  2545. return array('code' => 1, 'content' => _t('_Empty'));
  2546. $mixedResult = $oProfile->checkAllowedProfileView();
  2547. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  2548. return array('code' => 2, 'content' => $mixedResult);
  2549. }
  2550. $sContent = $this->_oTemplate->getPost($aEvent, $aParams);
  2551. if(empty($sContent))
  2552. return array('code' => 2, 'content' => _t('_Access denied'));
  2553. $sKey = 'allowed_view';
  2554. if(isset($aEvent[$sKey]) && $aEvent[$sKey] !== CHECK_ACTION_RESULT_ALLOWED)
  2555. return array('code' => 2, 'content' => $aEvent[$sKey]);
  2556. if($this->isAllowedView($aEvent) !== true)
  2557. return array('code' => 2, 'content' => _t('_Access denied'));
  2558. return array('code' => 0, 'content' => $sContent, 'event' => $aEvent);
  2559. }
  2560. public function deleteEvent($aEvent)
  2561. {
  2562. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->deleteEvent(array('id' => (int)$aEvent['id'])))
  2563. return false;
  2564. $this->onDelete($aEvent);
  2565. return true;
  2566. }
  2567. public function addAttachLink($aValues, $sDisplay = false)
  2568. {
  2569. $CNF = &$this->_oConfig->CNF;
  2570. if(!$sDisplay)
  2571. $sDisplay = $this->_oConfig->getObject('form_display_attach_link_add');
  2572. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $sDisplay, $this->_oTemplate);
  2573. if(!$oForm)
  2574. return array('message' => '_sys_txt_error_occured');
  2575. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  2576. $oForm->aParams['csrf']['disable'] = true;
  2577. if(!empty($oForm->aParams['db']['submit_name'])) {
  2578. $sSubmitName = $oForm->aParams['db']['submit_name'];
  2579. if(!isset($oForm->aInputs[$sSubmitName])) {
  2580. if(isset($oForm->aInputs[$CNF['FIELD_CONTROLS']]))
  2581. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  2582. if(!is_numeric($mixedIndex) || empty($aInput['name']) || $aInput['name'] != $sSubmitName)
  2583. continue;
  2584. $aValues[$sSubmitName] = $aInput['value'];
  2585. }
  2586. }
  2587. else
  2588. $aValues[$sSubmitName] = $oForm->aInputs[$sSubmitName]['value'];
  2589. }
  2590. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  2591. $oForm->initChecker(array(), $aValues);
  2592. if(!$oForm->isSubmittedAndValid())
  2593. return array('message' => '_sys_txt_error_occured');
  2594. return $this->_addLink($oForm);
  2595. }
  2596. public function getFormAttachLink($iEventId = 0)
  2597. {
  2598. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $this->_oConfig->getObject('form_display_attach_link_add'), $this->_oTemplate);
  2599. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_attach_link_form/';
  2600. $oForm->aInputs['event_id']['value'] = $iEventId;
  2601. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  2602. $oForm->initChecker();
  2603. if($oForm->isSubmittedAndValid())
  2604. return $this->_addLink($oForm);
  2605. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  2606. }
  2607. public function getFormPost($aParams = array())
  2608. {
  2609. $CNF = &$this->_oConfig->CNF;
  2610. $iUserId = $this->getUserId();
  2611. $oForm = $this->getFormPostObject($aParams);
  2612. $aFormInitCheckerParams = array();
  2613. $bValues = !empty($aParams['values']) && is_array($aParams['values']);
  2614. if($bValues) {
  2615. $this->_prepareFormForAutoSubmit($oForm, $aParams['values']);
  2616. $aFormInitCheckerParams = array(array(), $aParams['values']);
  2617. unset($aParams['values']);
  2618. }
  2619. call_user_func_array(array($oForm, 'initChecker'), $aFormInitCheckerParams);
  2620. $bAjaxMode = $oForm->isAjaxMode();
  2621. $bDynamicMode = $bAjaxMode;
  2622. if($oForm->isSubmittedAndValid()) {
  2623. $sType = $oForm->getCleanValue('type');
  2624. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  2625. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  2626. $aContent = array();
  2627. //--- Process Text ---//
  2628. $sText = $oForm->getCleanValue('text');
  2629. $sText = $this->_prepareTextForSave($sText);
  2630. $bText = !empty($sText);
  2631. if($bText)
  2632. $aContent['text'] = $sText;
  2633. //--- Process Context and Privacy ---//
  2634. $iOwnerId = (int)$oForm->getCleanValue('owner_id');
  2635. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  2636. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  2637. if(empty($iObjectPrivacyView))
  2638. $iObjectPrivacyView = $iObjectPrivacyViewDefault;
  2639. else if($iObjectPrivacyView < 0)
  2640. $iOwnerId = abs($iObjectPrivacyView);
  2641. //--- Process Link ---//
  2642. $aLinkIds = $oForm->getCleanValue($CNF['FIELD_LINK']);
  2643. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  2644. //--- Process Photos ---//
  2645. $aPhotoIds = $oForm->getCleanValue($CNF['FIELD_PHOTO']);
  2646. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  2647. //--- Process Videos ---//
  2648. $aVideoIds = $oForm->getCleanValue($CNF['FIELD_VIDEO']);
  2649. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  2650. //--- Process Files ---//
  2651. $aFileIds = $oForm->getCleanValue($CNF['FIELD_FILE']);
  2652. $bFileIds = !empty($aFileIds) && is_array($aFileIds);
  2653. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds && !$bFileIds) {
  2654. $oForm->aInputs['text']['error'] = _t('_bx_timeline_txt_err_empty_post');
  2655. $oForm->setValid(false);
  2656. return $this->_prepareResponse(array('form' => $oForm->getCode($bDynamicMode), 'form_id' => $oForm->id), $bAjaxMode);
  2657. }
  2658. $sTitle = $bText ? $this->_oConfig->getTitle($sText) : $this->_oConfig->getTitleDefault($bLinkIds, $bPhotoIds, $bVideoIds, $bFileIds);
  2659. $sDescription = _t('_bx_timeline_txt_user_added_sample', '{profile_name}', _t('_bx_timeline_txt_sample_with_article'));
  2660. /**
  2661. * Unset 'text' input because its data was already processed
  2662. * and will be saved via additional values which were passed
  2663. * to BxDolForm::insert method.
  2664. */
  2665. unset($oForm->aInputs['text']);
  2666. $iId = $oForm->insert(array(
  2667. 'owner_id' => $iOwnerId,
  2668. 'object_id' => $iUserId,
  2669. 'object_owner_id' => $iUserId,
  2670. 'object_privacy_view' => $iObjectPrivacyView,
  2671. 'content' => serialize($aContent),
  2672. 'title' => $sTitle,
  2673. 'description' => $sDescription
  2674. ));
  2675. if(!empty($iId)) {
  2676. $aContent = array_merge($aContent, array(
  2677. 'timeline_group' => array(
  2678. 'by' => $this->getName() . '_' . $iUserId . '_' . $iId,
  2679. 'field' => 'owner_id'
  2680. )
  2681. ));
  2682. $this->_oDb->updateEvent(array('content' => serialize($aContent)), array('id' => $iId));
  2683. //--- Process Meta ---//
  2684. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  2685. if($bText)
  2686. $oMetatags->metaAdd($iId, $sText);
  2687. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  2688. //--- Process Link ---//
  2689. if($bLinkIds)
  2690. foreach($aLinkIds as $iLinkId)
  2691. $this->_oDb->saveLink($iId, $iLinkId);
  2692. //--- Process Media ---//
  2693. $this->_saveMedia($CNF['FIELD_PHOTO'], $iId, $aPhotoIds, $iUserId, true);
  2694. $this->_saveMedia($CNF['FIELD_VIDEO'], $iId, $aVideoIds, $iUserId, true);
  2695. $this->_saveMedia($CNF['FIELD_FILE'], $iId, $aFileIds, $iUserId, true);
  2696. $this->onPost($iId);
  2697. return $this->_prepareResponse(array('id' => $iId), $bAjaxMode, array(
  2698. 'redirect' => $this->_oConfig->getItemViewUrl(array('id' => $iId))
  2699. ));
  2700. }
  2701. return $this->_prepareResponse(array('message' => _t('_bx_timeline_txt_err_cannot_perform_action')), $bAjaxMode);
  2702. }
  2703. return $this->_prepareResponse(array('form' => $oForm->getCode($bDynamicMode), 'form_id' => $oForm->id), $bAjaxMode && $oForm->isSubmitted());
  2704. }
  2705. public function getFormEdit($iId, $aParams = array(), $aBrowseParams = array())
  2706. {
  2707. $CNF = &$this->_oConfig->CNF;
  2708. $sJsObjectView = $this->_oConfig->getJsObjectView($aBrowseParams);
  2709. $iUserId = $this->getUserId();
  2710. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  2711. if(empty($aEvent) || !is_array($aEvent))
  2712. return array();
  2713. $aContent = unserialize($aEvent['content']);
  2714. if(is_array($aContent) && !empty($aContent['text']))
  2715. $aEvent['text'] = $aContent['text'];
  2716. if(empty($aParams['form_object']))
  2717. $aParams['form_object'] = 'form_post';
  2718. if(empty($aParams['form_display']))
  2719. $aParams['form_display'] = 'form_display_post_edit';
  2720. $oForm = $this->getFormPostObject($aParams);
  2721. $oForm->setId($this->_oConfig->getHtmlIds('view', 'edit_form') . $iId);
  2722. $aFormInitCheckerParams = array();
  2723. $bValues = !empty($aParams['values']) && is_array($aParams['values']);
  2724. if($bValues) {
  2725. $this->_prepareFormForAutoSubmit($oForm, $aParams['values']);
  2726. $aFormInitCheckerParams = array(array(), array_merge($aEvent, $aParams['values']));
  2727. unset($aParams['values']);
  2728. }
  2729. else {
  2730. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'edit/' . $iId ;
  2731. if(!empty($aBrowseParams) && is_array($aBrowseParams))
  2732. $oForm->aFormAttrs['action'] = $this->_oConfig->addBrowseParams($oForm->aFormAttrs['action'], $aBrowseParams);
  2733. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  2734. if(!is_numeric($mixedIndex))
  2735. continue;
  2736. $oForm->aInputs[$CNF['FIELD_CONTROLS']][$mixedIndex]['attrs'] = bx_replace_markers($aInput['attrs'], array(
  2737. 'js_object_view' => $sJsObjectView,
  2738. 'content_id' => $iId
  2739. ));
  2740. }
  2741. $aFormInitCheckerParams = array($aEvent);
  2742. }
  2743. call_user_func_array(array($oForm, 'initChecker'), $aFormInitCheckerParams);
  2744. $bAjaxMode = $oForm->isAjaxMode();
  2745. $bDynamicMode = $bAjaxMode || bx_is_dynamic_request();
  2746. $sCodeAdd = '';
  2747. if($bDynamicMode) {
  2748. $sCodeAdd .= $this->_oTemplate->getAddedJs('post', $bDynamicMode);
  2749. $sCodeAdd .= $this->_oTemplate->getJsCode('post', array(), true, $bDynamicMode);
  2750. }
  2751. if($oForm->isSubmittedAndValid()) {
  2752. $aContent = array();
  2753. //--- Process Text ---//
  2754. $sText = $oForm->getCleanValue('text');
  2755. $sText = $this->_prepareTextForSave($sText);
  2756. $bText = !empty($sText);
  2757. unset($oForm->aInputs['text']);
  2758. if($bText)
  2759. $aContent['text'] = $sText;
  2760. $aValsToAdd = array(
  2761. 'content' => serialize($aContent)
  2762. );
  2763. //--- Process Privacy ---//
  2764. if(isset($oForm->aInputs[$CNF['FIELD_OBJECT_PRIVACY_VIEW']])) {
  2765. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  2766. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  2767. if(empty($iObjectPrivacyView))
  2768. $aValsToAdd = array_merge($aValsToAdd, array(
  2769. 'object_privacy_view' => $iObjectPrivacyViewDefault
  2770. ));
  2771. else if($iObjectPrivacyView < 0)
  2772. $aValsToAdd = array_merge($aValsToAdd, array(
  2773. 'owner_id' => abs($iObjectPrivacyView)
  2774. ));
  2775. }
  2776. //--- Process Link ---//
  2777. $aLinkIds = $oForm->getCleanValue($CNF['FIELD_LINK']);
  2778. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  2779. //--- Process Media ---//
  2780. $aPhotoIds = $oForm->getCleanValue($CNF['FIELD_PHOTO']);
  2781. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  2782. $aVideoIds = $oForm->getCleanValue($CNF['FIELD_VIDEO']);
  2783. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  2784. if($bVideoIds)
  2785. $aValsToAdd[$CNF['FIELD_STATUS']] = 'awaiting';
  2786. $aFileIds = $oForm->getCleanValue($CNF['FIELD_FILE']);
  2787. $bFileIds = !empty($aFileIds) && is_array($aFileIds);
  2788. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds && !$bFileIds) {
  2789. $oForm->aInputs['text']['error'] = _t('_bx_timeline_txt_err_empty_post');
  2790. $oForm->setValid(false);
  2791. return $this->_prepareResponse(array('form' => $sCodeAdd . $oForm->getCode($bDynamicMode), 'form_id' => $oForm->id), $bAjaxMode);
  2792. }
  2793. if($oForm->update($iId, $aValsToAdd) === false)
  2794. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  2795. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  2796. if($bText)
  2797. $oMetatags->metaAdd($iId, $sText);
  2798. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  2799. //--- Process Link ---//
  2800. if($bLinkIds)
  2801. foreach($aLinkIds as $iLinkId)
  2802. $this->_oDb->saveLink($iId, $iLinkId);
  2803. //--- Process Media ---//
  2804. $this->_saveMedia($CNF['FIELD_PHOTO'], $iId, $aPhotoIds, $iUserId);
  2805. $this->_saveMedia($CNF['FIELD_VIDEO'], $iId, $aVideoIds, $iUserId);
  2806. $this->_saveMedia($CNF['FIELD_FILE'], $iId, $aFileIds, $iUserId);
  2807. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iId);
  2808. return array(
  2809. 'id' => $iId
  2810. );
  2811. }
  2812. return array(
  2813. 'id' => $iId,
  2814. 'form' => $sCodeAdd . $oForm->getCode($bDynamicMode),
  2815. 'form_id' => $oForm->id,
  2816. 'eval' => $sJsObjectView . '.onEditPost(oData)'
  2817. );
  2818. }
  2819. public function getFormPostObject($aParams)
  2820. {
  2821. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  2822. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_add';
  2823. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  2824. /**
  2825. * Note. 'ajax_mode' parameter isn't checked because
  2826. * timeline post form works as Ajax form by default.
  2827. */
  2828. $sParamsKey = 'visibility_autoselect';
  2829. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  2830. $oForm->setVisibilityAutoselect((bool)$aParams[$sParamsKey]);
  2831. $oForm->init();
  2832. return $oForm;
  2833. }
  2834. public function getCmtsObject($sSystem, $iId)
  2835. {
  2836. if(empty($sSystem) || (int)$iId == 0)
  2837. return false;
  2838. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2839. if(!$oCmts || !$oCmts->isEnabled())
  2840. return false;
  2841. return $oCmts;
  2842. }
  2843. public function getViewObject($sSystem, $iId)
  2844. {
  2845. if(empty($sSystem) || (int)$iId == 0)
  2846. return false;
  2847. $oView = BxDolView::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2848. if(!$oView || !$oView->isEnabled())
  2849. return false;
  2850. return $oView;
  2851. }
  2852. public function getVoteObject($sSystem, $iId)
  2853. {
  2854. if(empty($sSystem) || (int)$iId == 0)
  2855. return false;
  2856. $oVote = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2857. if(!$oVote || !$oVote->isEnabled())
  2858. return false;
  2859. return $oVote;
  2860. }
  2861. public function getReactionObject($sSystem, $iId)
  2862. {
  2863. if(empty($sSystem) || (int)$iId == 0)
  2864. return false;
  2865. $oReaction = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2866. if(!$oReaction || !$oReaction->isEnabled())
  2867. return false;
  2868. return $oReaction;
  2869. }
  2870. public function getScoreObject($sSystem, $iId)
  2871. {
  2872. if(empty($sSystem) || (int)$iId == 0)
  2873. return false;
  2874. $oScore = BxDolScore::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2875. if(!$oScore || !$oScore->isEnabled())
  2876. return false;
  2877. return $oScore;
  2878. }
  2879. public function getReportObject($sSystem, $iId)
  2880. {
  2881. if(empty($sSystem) || (int)$iId == 0)
  2882. return false;
  2883. $oReport = BxDolReport::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2884. if(!$oReport || !$oReport->isEnabled())
  2885. return false;
  2886. return $oReport;
  2887. }
  2888. public function getAttachmentsMenuObject()
  2889. {
  2890. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post_attachments'), $this->_oTemplate);
  2891. }
  2892. public function getManageMenuObject()
  2893. {
  2894. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'), $this->_oTemplate);
  2895. }
  2896. public function getCacheItemObject()
  2897. {
  2898. $oCacheEngine = bx_instance('BxDolCache' . $this->_oConfig->getCacheItemEngine());
  2899. if(!$oCacheEngine->isAvailable())
  2900. $oCacheEngine = bx_instance('BxDolCacheFile');
  2901. return $oCacheEngine;
  2902. }
  2903. public function getConnectionMuteObject()
  2904. {
  2905. return BxDolConnection::getObjectInstance($this->_oConfig->getObject('connection_mute'));
  2906. }
  2907. //--- Check permissions methods ---//
  2908. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  2909. {
  2910. if(!$iProfileId)
  2911. $iProfileId = $this->_iProfileId;
  2912. $CNF = &$this->_oConfig->CNF;
  2913. // moderator and owner always have access
  2914. $iOwnerId = (int)$aDataEntry['owner_id'];
  2915. if(!empty($iProfileId) && (abs($iOwnerId) == (int)$iProfileId || $this->isModerator()))
  2916. return CHECK_ACTION_RESULT_ALLOWED;
  2917. // check ACL
  2918. if($iOwnerId != 0 && ($oOwner = BxDolProfile::getInstanceMagic($iOwnerId)) !== false) {
  2919. $mixedCheckResult = BxDolService::call($oOwner->getModule(), 'check_allowed_with_content_for_profile', array('view', $oOwner->getContentId(), $iProfileId));
  2920. if($mixedCheckResult !== CHECK_ACTION_RESULT_ALLOWED)
  2921. return $mixedCheckResult;
  2922. }
  2923. // check privacy
  2924. if(!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  2925. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  2926. if($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  2927. return _t('_sys_access_denied_to_private_content');
  2928. }
  2929. // check alert to allow custom checks
  2930. $mixedResult = null;
  2931. bx_alert('system', 'check_allowed_view', 0, 0, array('module' => $this->getName(), 'content_info' => $aDataEntry, 'profile_id' => $iProfileId, 'override_result' => &$mixedResult));
  2932. if($mixedResult !== null)
  2933. return $mixedResult;
  2934. return CHECK_ACTION_RESULT_ALLOWED;
  2935. }
  2936. public function isModerator()
  2937. {
  2938. $sModule = $this->getName();
  2939. $iUserId = (int)$this->getUserId();
  2940. $aCheckResult = checkActionModule($iUserId, 'edit', $sModule);
  2941. if($aCheckResult[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2942. return true;
  2943. $aCheckResult = checkActionModule($iUserId, 'delete', $sModule);
  2944. if($aCheckResult[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2945. return true;
  2946. return false;
  2947. }
  2948. public function isAllowedPost($bPerform = false)
  2949. {
  2950. if(isAdmin())
  2951. return true;
  2952. $iUserId = $this->getUserId();
  2953. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  2954. if($aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  2955. return $aCheckResult[CHECK_ACTION_MESSAGE];
  2956. if(!empty($this->_iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId)) !== false) {
  2957. if($oProfileOwner->checkAllowedPostInProfile($this->_iOwnerId, $this->getName()) !== CHECK_ACTION_RESULT_ALLOWED)
  2958. return _t('_sys_txt_access_denied');
  2959. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_post', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2960. }
  2961. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2962. }
  2963. public function isAllowedView($aEvent, $bPerform = false)
  2964. {
  2965. $CNF = $this->_oConfig->CNF;
  2966. if((int)$aEvent[$CNF['FIELD_OWNER_ID']] == 0)
  2967. return true;
  2968. $oProfileOwner = BxDolProfile::getInstance($aEvent[$CNF['FIELD_OWNER_ID']]);
  2969. if($oProfileOwner && $oProfileOwner->checkAllowedProfileView() !== CHECK_ACTION_RESULT_ALLOWED)
  2970. return false;
  2971. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->getObject('privacy_view'));
  2972. if(!$oPrivacy)
  2973. return true;
  2974. $oPrivacy->setTableFieldAuthor($this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? 'owner_id' : 'object_id');
  2975. return $oPrivacy->check($aEvent[$CNF['FIELD_ID']]);
  2976. }
  2977. public function isAllowedEdit($aEvent, $bPerform = false)
  2978. {
  2979. if(!isLogged())
  2980. return false;
  2981. //--- System posts and Reposts cannot be edited at all.
  2982. if(!$this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) || $aEvent['type'] == $this->_oConfig->getPrefix('common_post') . 'repost')
  2983. return false;
  2984. if(isAdmin())
  2985. return true;
  2986. $iUserId = (int)$this->getUserId();
  2987. $iOwnerId = (int)$aEvent['owner_id'];
  2988. $iObjectId = abs((int)$aEvent['object_id']);
  2989. if($iObjectId == $iUserId && $this->_oConfig->isAllowEdit())
  2990. return true;
  2991. $aCheckResult = checkActionModule($iUserId, 'edit', $this->getName(), $bPerform);
  2992. if(!empty($iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($iOwnerId)) !== false) {
  2993. if (BxDolService::call($oProfileOwner->getModule(), 'check_allowed_module_action_in_profile', array($oProfileOwner->getContentId(), $this->getName(), 'edit_any')) === CHECK_ACTION_RESULT_ALLOWED) {
  2994. return true;
  2995. }
  2996. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_edit', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2997. }
  2998. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2999. }
  3000. public function isAllowedDelete($aEvent, $bPerform = false)
  3001. {
  3002. if(!isLogged())
  3003. return false;
  3004. if(isAdmin())
  3005. return true;
  3006. $iUserId = (int)$this->getUserId();
  3007. $iOwnerId = (int)$aEvent['owner_id'];
  3008. $iObjectId = abs((int)$aEvent['object_id']);
  3009. if((($iOwnerId == $iUserId && $this->_oConfig->isAllowDelete()) || ($this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && $iObjectId == $iUserId)))
  3010. return true;
  3011. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  3012. if(!empty($iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($iOwnerId)) !== false) {
  3013. if (BxDolService::call($oProfileOwner->getModule(), 'check_allowed_module_action_in_profile', array($oProfileOwner->getContentId(), $this->getName(), 'delete_any')) === CHECK_ACTION_RESULT_ALLOWED) {
  3014. return true;
  3015. }
  3016. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_delete', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3017. }
  3018. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3019. }
  3020. public function isAllowedComment($aEvent, $bPerform = false)
  3021. {
  3022. $mixedComments = $this->getCommentsData($aEvent['comments']);
  3023. if($mixedComments === false)
  3024. return false;
  3025. list($sSystem, $iObjectId) = $mixedComments;
  3026. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  3027. if($oCmts->isViewAllowed() !== CHECK_ACTION_RESULT_ALLOWED)
  3028. return false;
  3029. $oCmts->addCssJs();
  3030. return true;
  3031. }
  3032. public function isAllowedViewCounter($aEvent, $bPerform = false)
  3033. {
  3034. $mixedViews = $this->getViewsData($aEvent['views']);
  3035. if($mixedViews === false)
  3036. return false;
  3037. list($sSystem, $iObjectId) = $mixedViews;
  3038. $oView = $this->getViewObject($sSystem, $iObjectId);
  3039. if(!$oView->isAllowedViewView($bPerform))
  3040. return false;
  3041. $bResult = true;
  3042. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3043. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view_counter', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3044. return $bResult;
  3045. }
  3046. public function isAllowedVote($aEvent, $bPerform = false)
  3047. {
  3048. $mixedVotes = $this->getVotesData($aEvent['votes']);
  3049. if($mixedVotes === false)
  3050. return false;
  3051. list($sSystem, $iObjectId) = $mixedVotes;
  3052. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  3053. if(!$oVote->isAllowedVote($bPerform))
  3054. return false;
  3055. $bResult = true;
  3056. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3057. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3058. return $bResult;
  3059. }
  3060. public function isAllowedVoteView($aEvent, $bPerform = false)
  3061. {
  3062. $mixedVotes = $this->getVotesData($aEvent['votes']);
  3063. if($mixedVotes === false)
  3064. return false;
  3065. list($sSystem, $iObjectId) = $mixedVotes;
  3066. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  3067. if(!$oVote->isAllowedVoteView($bPerform))
  3068. return false;
  3069. $bResult = true;
  3070. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3071. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote_view', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3072. return $bResult;
  3073. }
  3074. public function isAllowedReaction($aEvent, $bPerform = false)
  3075. {
  3076. $mixedReactions = $this->getReactionsData($aEvent['reactions']);
  3077. if($mixedReactions === false)
  3078. return false;
  3079. list($sSystem, $iObjectId) = $mixedReactions;
  3080. $oReaction = $this->getReactionObject($sSystem, $iObjectId);
  3081. if(!$oReaction->isAllowedVote($bPerform))
  3082. return false;
  3083. $bResult = true;
  3084. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3085. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_reaction', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3086. return $bResult;
  3087. }
  3088. public function isAllowedReactionView($aEvent, $bPerform = false)
  3089. {
  3090. $mixedReactions = $this->getReactionsData($aEvent['reactions']);
  3091. if($mixedReactions === false)
  3092. return false;
  3093. list($sSystem, $iObjectId) = $mixedReactions;
  3094. $oReaction = $this->getReactionObject($sSystem, $iObjectId);
  3095. if(!$oReaction->isAllowedVoteView($bPerform))
  3096. return false;
  3097. $bResult = true;
  3098. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3099. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_reaction_view', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3100. return $bResult;
  3101. }
  3102. public function isAllowedScore($aEvent, $bPerform = false)
  3103. {
  3104. $mixedScores = $this->getScoresData($aEvent['scores']);
  3105. if($mixedScores === false)
  3106. return false;
  3107. list($sSystem, $iObjectId) = $mixedScores;
  3108. $oScore = $this->getScoreObject($sSystem, $iObjectId);
  3109. if(!$oScore->isAllowedVote($bPerform))
  3110. return false;
  3111. $bResult = true;
  3112. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3113. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_score', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3114. return $bResult;
  3115. }
  3116. public function isAllowedReport($aEvent, $bPerform = false)
  3117. {
  3118. $mixedReports = $this->getReportsData($aEvent['reports']);
  3119. if($mixedReports === false)
  3120. return false;
  3121. list($sSystem, $iObjectId) = $mixedReports;
  3122. $oReport = $this->getReportObject($sSystem, $iObjectId);
  3123. if(!$oReport->isAllowedReport($bPerform))
  3124. return false;
  3125. $bResult = true;
  3126. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3127. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_report', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3128. return $bResult;
  3129. }
  3130. public function isAllowedRepost($aEvent, $bPerform = false)
  3131. {
  3132. $iUserId = (int)$this->getUserId();
  3133. if($iUserId == 0)
  3134. return false;
  3135. $iPrivacy = (int)$aEvent['object_privacy_view'];
  3136. if($iPrivacy >= 0 && !in_array($iPrivacy, array(BX_DOL_PG_ALL, BX_DOL_PG_MEMBERS)))
  3137. return false;
  3138. if(isAdmin())
  3139. return true;
  3140. $aCheckResult = checkActionModule($iUserId, 'repost', $this->getName(), $bPerform);
  3141. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3142. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_repost', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3143. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3144. }
  3145. public function isAllowedSend($aEvent, $bPerform = false)
  3146. {
  3147. if(!$this->_oDb->isEnabledByName('bx_convos'))
  3148. return false;
  3149. if(isAdmin())
  3150. return true;
  3151. $iUserId = (int)$this->getUserId();
  3152. if($iUserId == 0)
  3153. return false;
  3154. $aCheckResult = checkActionModule($iUserId, 'send', $this->getName(), $bPerform);
  3155. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3156. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_send', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3157. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3158. }
  3159. public function isAllowedMute($aEvent, $bPerform = false)
  3160. {
  3161. $CNF = &$this->_oConfig->CNF;
  3162. if(!empty($aEvent[$CNF['FIELD_OWNER_ID']]) && $aEvent[$CNF['FIELD_OWNER_ID']] != $this->_iProfileId)
  3163. return false;
  3164. $iAuthor = (int)$aEvent[$CNF['FIELD_OWNER_ID']];
  3165. if(!$this->_oConfig->isSystem($aEvent['type'], $aEvent['action']))
  3166. $iAuthor = (int)$aEvent[$CNF['FIELD_OBJECT_ID']];
  3167. if($this->_iProfileId == $iAuthor || $this->getConnectionMuteObject()->isConnected($this->_iProfileId, $iAuthor))
  3168. return false;
  3169. return $this->_isAllowedMute($bPerform);
  3170. }
  3171. public function isAllowedUnmute($iAuthor, $bPerform = false)
  3172. {
  3173. if(!$this->getConnectionMuteObject()->isConnected($this->_iProfileId, $iAuthor))
  3174. return false;
  3175. return $this->_isAllowedMute($bPerform);
  3176. }
  3177. /**
  3178. * Pin - "Pin here" - pin the post on Profile Timeline for profile owner.
  3179. * Can be done by profile owner for himself or by admin for profile owner to see.
  3180. * @param type $aEvent
  3181. * @param type $bPerform
  3182. * @return boolean
  3183. */
  3184. public function isAllowedPin($aEvent, $bPerform = false)
  3185. {
  3186. if((int)$aEvent['pinned'] != 0)
  3187. return false;
  3188. return $this->_isAllowedPin($aEvent, $bPerform);
  3189. }
  3190. public function isAllowedUnpin($aEvent, $bPerform = false)
  3191. {
  3192. if((int)$aEvent['pinned'] == 0)
  3193. return false;
  3194. return $this->_isAllowedPin($aEvent, $bPerform);
  3195. }
  3196. /**
  3197. * Stick - "Pin for All" - pin the post on Public Timeline for everybody to see.
  3198. * Is available for Administrators/Moderators only.
  3199. * @param type $aEvent
  3200. * @param type $bPerform
  3201. * @return boolean
  3202. */
  3203. public function isAllowedStick($aEvent, $bPerform = false)
  3204. {
  3205. if((int)$aEvent['sticked'] != 0)
  3206. return false;
  3207. return $this->_isAllowedStick($aEvent, $bPerform);
  3208. }
  3209. public function isAllowedUnstick($aEvent, $bPerform = false)
  3210. {
  3211. if((int)$aEvent['sticked'] == 0)
  3212. return false;
  3213. return $this->_isAllowedStick($aEvent, $bPerform);
  3214. }
  3215. public function isAllowedPromote($aEvent, $bPerform = false)
  3216. {
  3217. if((int)$aEvent['promoted'] != 0)
  3218. return false;
  3219. return $this->_isAllowedPromote($aEvent, $bPerform);
  3220. }
  3221. public function isAllowedUnpromote($aEvent, $bPerform = false)
  3222. {
  3223. if((int)$aEvent['promoted'] == 0)
  3224. return false;
  3225. return $this->_isAllowedPromote($aEvent, $bPerform);
  3226. }
  3227. public function isAllowedMore($aEvent, $bPerform = false)
  3228. {
  3229. $oMoreMenu = $this->getManageMenuObject();
  3230. if(!$oMoreMenu)
  3231. return false;
  3232. $oMoreMenu->setEvent($aEvent);
  3233. return $oMoreMenu->isVisible();
  3234. }
  3235. public function checkAllowedView ($aContentInfo, $isPerformAction = false)
  3236. {
  3237. if(!$this->isAllowedView($aContentInfo, $isPerformAction))
  3238. return _t('_sys_txt_access_denied');
  3239. return CHECK_ACTION_RESULT_ALLOWED;
  3240. }
  3241. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  3242. {
  3243. $CNF = $this->_oConfig->CNF;
  3244. $iOwner = (int)$aContentInfo[$CNF['FIELD_OWNER_ID']];
  3245. if($iOwner == 0) //--- in case of Public Timeline.
  3246. return CHECK_ACTION_RESULT_ALLOWED;
  3247. $oOwner = BxDolProfile::getInstance($iOwner);
  3248. if(!$oOwner) //--- in case of non-existed Timeline owner.
  3249. return _t('_sys_txt_access_denied');
  3250. $mixedResult = $oOwner->checkAllowedProfileView();
  3251. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  3252. return $mixedResult;
  3253. return $this->checkAllowedView($aContentInfo, $isPerformAction);
  3254. }
  3255. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  3256. {
  3257. $sError = '_sys_txt_access_denied';
  3258. $aContentInfo = array_merge($aContentInfo, $this->_oTemplate->getDataCached($aContentInfo));
  3259. if($aContentInfo === false)
  3260. return _t($sError);
  3261. if(!$this->isAllowedComment($aContentInfo, $isPerformAction))
  3262. return _t($sError);
  3263. return CHECK_ACTION_RESULT_ALLOWED;
  3264. }
  3265. public function checkAllowedEditAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  3266. {
  3267. if(!$iProfileId)
  3268. $iProfileId = $this->_iProfileId;
  3269. $aCheck = checkActionModule($iProfileId, 'edit', $this->getName(), $isPerformAction);
  3270. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  3271. return CHECK_ACTION_RESULT_ALLOWED;
  3272. return _t('_sys_txt_access_denied');
  3273. }
  3274. public function onPost($iContentId)
  3275. {
  3276. $CNF = &$this->_oConfig->CNF;
  3277. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  3278. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  3279. //--- Request event's data from content module and update it in the Timeline DB.
  3280. $this->_oTemplate->getDataCached($aEvent);
  3281. $sPostType = 'system';
  3282. $iSenderId = $iObjectAuthorId = (int)$aEvent['owner_id'];
  3283. }
  3284. else {
  3285. $sPostType = 'common';
  3286. $iSenderId = $iObjectAuthorId = (int)$aEvent['object_id'];
  3287. }
  3288. //--- Event -> Post/Defer for Alerts Engine ---//
  3289. $sAction = ($aEvent[$CNF['FIELD_STATUS']] == BX_TIMELINE_STATUS_AWAITING ? 'defer' : 'post') . '_' . $sPostType;
  3290. bx_alert($this->_oConfig->getObject('alert'), $sAction, $iContentId, $iSenderId, array(
  3291. 'owner_id' => $aEvent['owner_id'],
  3292. 'object_author_id' => $iObjectAuthorId,
  3293. 'privacy_view' => $aEvent['object_privacy_view'],
  3294. ));
  3295. //--- Event -> Post for Alerts Engine ---//
  3296. }
  3297. public function onPublished($iContentId)
  3298. {
  3299. //--- Clear Item cache
  3300. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iContentId);
  3301. $this->onPost($iContentId);
  3302. }
  3303. public function onFailed($iContentId)
  3304. {
  3305. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  3306. //--- Clear Item cache
  3307. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iContentId);
  3308. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  3309. //--- Request event's data from content module and update it in the Timeline DB.
  3310. $this->_oTemplate->getDataCached($aEvent);
  3311. $sPostType = 'system';
  3312. $iSenderId = $iObjectAuthorId = (int)$aEvent['owner_id'];
  3313. }
  3314. else {
  3315. $sPostType = 'common';
  3316. $iSenderId = $iObjectAuthorId = (int)$aEvent['object_id'];
  3317. }
  3318. //--- Event -> Fail for Alerts Engine ---//
  3319. bx_alert($this->_oConfig->getObject('alert'), 'fail_' . $sPostType, $iContentId, $iSenderId, array(
  3320. 'owner_id' => $aEvent['owner_id'],
  3321. 'object_author_id' => $iObjectAuthorId,
  3322. 'privacy_view' => $aEvent['object_privacy_view'],
  3323. ));
  3324. //--- Event -> Post for Alerts Engine ---//
  3325. }
  3326. public function onRepost($iContentId, $aReposted = array())
  3327. {
  3328. $CNF = &$this->_oConfig->CNF;
  3329. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  3330. if(empty($aReposted)) {
  3331. $aContent = unserialize($aEvent['content']);
  3332. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  3333. if(empty($aReposted) || !is_array($aReposted))
  3334. return;
  3335. }
  3336. $iUserId = (int)$aEvent[$CNF['FIELD_OBJECT_OWNER_ID']];
  3337. $this->_oDb->insertRepostTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aReposted['id']);
  3338. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts']);
  3339. //--- Timeline -> Update for Alerts Engine ---//
  3340. bx_alert($this->_oConfig->getObject('alert'), 'repost', $aReposted['id'], $iUserId, array(
  3341. 'privacy_view' => $aEvent['object_privacy_view'],
  3342. 'object_author_id' => $aReposted['owner_id'],
  3343. 'repost_id' => $iContentId,
  3344. ));
  3345. //--- Timeline -> Update for Alerts Engine ---//
  3346. }
  3347. public function onDelete($aEvent)
  3348. {
  3349. $CNF = &$this->_oConfig->CNF;
  3350. $iUserId = $this->getUserId();
  3351. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  3352. $sCommonPostComment = $this->_oConfig->getObject('comment');
  3353. //--- Delete comments for Common posts.
  3354. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  3355. $oComments = $this->getCmtsObject($sCommonPostComment, $aEvent[$CNF['FIELD_ID']]);
  3356. if($oComments !== false)
  3357. $oComments->onObjectDelete($aEvent[$CNF['FIELD_ID']]);
  3358. }
  3359. //--- Delete attached photos, videos and links when common event was deleted.
  3360. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  3361. $this->_deleteMedia($CNF['FIELD_PHOTO'], $aEvent[$CNF['FIELD_ID']]);
  3362. $this->_deleteMedia($CNF['FIELD_VIDEO'], $aEvent[$CNF['FIELD_ID']]);
  3363. $this->_deleteMedia($CNF['FIELD_FILE'], $aEvent[$CNF['FIELD_ID']]);
  3364. $this->_deleteLinks($aEvent[$CNF['FIELD_ID']]);
  3365. }
  3366. //--- Update parent event when repost event was deleted.
  3367. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  3368. if($bRepost) {
  3369. $this->_oDb->deleteRepostTrack($aEvent[$CNF['FIELD_ID']]);
  3370. $aContent = unserialize($aEvent['content']);
  3371. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  3372. if(!empty($aReposted) && is_array($aReposted))
  3373. $this->_oDb->updateRepostCounter($aReposted[$CNF['FIELD_ID']], $aReposted['reposts'], -1);
  3374. }
  3375. //--- Find and delete repost events when parent event was deleted.
  3376. $bSystem = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']);
  3377. $aRepostEvents = $this->_oDb->getEvents(array('browse' => 'reposted_by_track', 'value' => $aEvent[$CNF['FIELD_ID']]));
  3378. foreach($aRepostEvents as $aRepostEvent) {
  3379. if((int)$this->_oDb->deleteEvent(array('id' => (int)$aRepostEvent[$CNF['FIELD_ID']])) == 0)
  3380. continue;
  3381. $this->_oDb->deleteRepostTrack($aRepostEvent[$CNF['FIELD_ID']]);
  3382. $oComments = $this->getCmtsObject($sCommonPostComment, $aRepostEvent[$CNF['FIELD_ID']]);
  3383. if($oComments !== false)
  3384. $oComments->onObjectDelete($aRepostEvent[$CNF['FIELD_ID']]);
  3385. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aEvent[$CNF['FIELD_ID']], $iUserId, array(
  3386. 'repost_id' => $aRepostEvent[$CNF['FIELD_ID']],
  3387. ));
  3388. }
  3389. //--- Delete associated meta.
  3390. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  3391. $oMetatags->onDeleteContent($aEvent[$CNF['FIELD_ID']]);
  3392. //--- Delete item cache.
  3393. $sCacheItemKey = $this->_oConfig->getCacheItemKey($aEvent[$CNF['FIELD_ID']]);
  3394. $this->getCacheItemObject()->delData($sCacheItemKey);
  3395. //--- Event -> Delete for Alerts Engine ---//
  3396. if($bRepost)
  3397. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aReposted[$CNF['FIELD_ID']], $iUserId, array(
  3398. 'repost_id' => $aEvent[$CNF['FIELD_ID']],
  3399. ));
  3400. else
  3401. bx_alert($this->_oConfig->getObject('alert'), 'delete', $aEvent[$CNF['FIELD_ID']], $iUserId);
  3402. //--- Event -> Delete for Alerts Engine ---//
  3403. }
  3404. public function getParams($sView = '', $sType = '', $iOwnerId = 0, $iStart = 0, $iPerPage = 0, $sFilter = BX_TIMELINE_FILTER_ALL, $aModules = array(), $iTimeline = 0)
  3405. {
  3406. return $this->_prepareParams(array(
  3407. 'view' => $sView,
  3408. 'type' => $sType,
  3409. 'owner_id' => $iOwnerId,
  3410. 'start' => $iStart,
  3411. 'per_page' => $iPerPage,
  3412. 'timeline' => $iTimeline,
  3413. 'filter' => $sFilter,
  3414. 'modules' => $aModules
  3415. ));
  3416. }
  3417. public function getParamsExt($aParams = array())
  3418. {
  3419. return $this->_prepareParams($aParams);
  3420. }
  3421. public function getViewsData(&$aViews)
  3422. {
  3423. if(empty($aViews) || !is_array($aViews))
  3424. return false;
  3425. $sSystem = isset($aViews['system']) ? $aViews['system'] : '';
  3426. $iObjectId = isset($aViews['object_id']) ? (int)$aViews['object_id'] : 0;
  3427. $iCount = isset($aViews['count']) ? (int)$aViews['count'] : 0;
  3428. if($sSystem == '' || $iObjectId == 0)
  3429. return false;
  3430. return array($sSystem, $iObjectId, $iCount);
  3431. }
  3432. public function getVotesData(&$aVotes)
  3433. {
  3434. if(empty($aVotes) || !is_array($aVotes))
  3435. return false;
  3436. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  3437. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  3438. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  3439. if($sSystem == '' || $iObjectId == 0)
  3440. return false;
  3441. return array($sSystem, $iObjectId, $iCount);
  3442. }
  3443. public function getReactionsData(&$aReactions)
  3444. {
  3445. if(empty($aReactions) || !is_array($aReactions))
  3446. return false;
  3447. $sSystem = isset($aReactions['system']) ? $aReactions['system'] : '';
  3448. $iObjectId = isset($aReactions['object_id']) ? (int)$aReactions['object_id'] : 0;
  3449. $iCount = isset($aReactions['count']) ? (int)$aReactions['count'] : 0;
  3450. if($sSystem == '' || $iObjectId == 0)
  3451. return false;
  3452. return array($sSystem, $iObjectId, $iCount);
  3453. }
  3454. public function getScoresData(&$aScores)
  3455. {
  3456. if(empty($aScores) || !is_array($aScores))
  3457. return false;
  3458. $sSystem = isset($aScores['system']) ? $aScores['system'] : '';
  3459. $iObjectId = isset($aScores['object_id']) ? (int)$aScores['object_id'] : 0;
  3460. $iScore = isset($aScores['score']) ? (int)$aScores['score'] : 0;
  3461. if($sSystem == '' || $iObjectId == 0)
  3462. return false;
  3463. return array($sSystem, $iObjectId, $iScore);
  3464. }
  3465. public function getReportsData(&$aReports)
  3466. {
  3467. if(empty($aReports) || !is_array($aReports))
  3468. return false;
  3469. $sSystem = isset($aReports['system']) ? $aReports['system'] : '';
  3470. $iObjectId = isset($aReports['object_id']) ? (int)$aReports['object_id'] : 0;
  3471. $iCount = isset($aReports['count']) ? (int)$aReports['count'] : 0;
  3472. if($sSystem == '' || $iObjectId == 0)
  3473. return false;
  3474. return array($sSystem, $iObjectId, $iCount);
  3475. }
  3476. public function getCommentsData(&$aComments)
  3477. {
  3478. if(empty($aComments) || !is_array($aComments))
  3479. return false;
  3480. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  3481. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  3482. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  3483. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  3484. return false;
  3485. return array($sSystem, $iObjectId, $iCount);
  3486. }
  3487. public function getEventLinks($iEventId)
  3488. {
  3489. $aLinks = $this->_oDb->getLinks($iEventId);
  3490. if(empty($aLinks) || !is_array($aLinks))
  3491. return array();
  3492. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_preview'));
  3493. $aResult = array();
  3494. foreach($aLinks as $aLink)
  3495. $aResult[] = array(
  3496. 'url' => $aLink['url'],
  3497. 'title' => $aLink['title'],
  3498. 'text' => $aLink['text'],
  3499. 'thumbnail' => (int)$aLink['media_id'] != 0 ? $oTranscoder->getFileUrl($aLink['media_id']) : ''
  3500. );
  3501. return $aResult;
  3502. }
  3503. public function getEventImages($iEventId)
  3504. {
  3505. $CNF = &$this->_oConfig->CNF;
  3506. $aPhotos = $this->_oDb->getMedia($CNF['FIELD_PHOTO'], $iEventId);
  3507. if(empty($aPhotos) || !is_array($aPhotos))
  3508. return array();
  3509. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_view'));
  3510. $oTranscoderMedium = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_medium'));
  3511. $oTranscoderBig = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_big'));
  3512. $aResult = array();
  3513. foreach($aPhotos as $iPhotoId) {
  3514. $sPhotoSrc = $oTranscoder->getFileUrl($iPhotoId);
  3515. $sPhotoSrcMedium = $oTranscoderMedium->getFileUrl($iPhotoId);
  3516. $sPhotoSrcBig = $oTranscoderBig->getFileUrl($iPhotoId);
  3517. if(empty($sPhotoSrcMedium) && !empty($sPhotoSrc))
  3518. $sPhotoSrcMedium = $sPhotoSrc;
  3519. if(empty($sPhotoSrcBig) && !empty($sPhotoSrcMedium))
  3520. $sPhotoSrcBig = $sPhotoSrcMedium;
  3521. $aResult[] = array(
  3522. 'id' => $iPhotoId,
  3523. 'src' => $sPhotoSrc,
  3524. 'src_medium' => $sPhotoSrcMedium,
  3525. 'src_orig' => $sPhotoSrcBig,
  3526. );
  3527. }
  3528. return $aResult;
  3529. }
  3530. public function getEventVideos($iEventId)
  3531. {
  3532. $CNF = &$this->_oConfig->CNF;
  3533. $aVideos = $this->_oDb->getMedia($CNF['FIELD_VIDEO'], $iEventId);
  3534. if(empty($aVideos) || !is_array($aVideos))
  3535. return array();
  3536. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_videos'));
  3537. $oTranscoderPoster = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_poster'));
  3538. $oTranscoderMp4 = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_mp4'));
  3539. $oTranscoderMp4Hd = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_mp4_hd'));
  3540. $aResult = array();
  3541. foreach($aVideos as $iVideoId) {
  3542. $sVideoUrl = $oStorage->getFileUrlById($iVideoId);
  3543. $aVideoFile = $oStorage->getFile($iVideoId);
  3544. $sVideoUrlHd = '';
  3545. if (!empty($aVideoFile['dimensions']) && $oTranscoderMp4Hd->isProcessHD($aVideoFile['dimensions']))
  3546. $sVideoUrlHd = $oTranscoderMp4Hd->getFileUrl($iVideoId);
  3547. $aResult[$iVideoId] = array(
  3548. 'id' => $iVideoId,
  3549. 'src_poster' => $oTranscoderPoster->getFileUrl($iVideoId),
  3550. 'src_mp4' => $oTranscoderMp4->getFileUrl($iVideoId),
  3551. 'src_mp4_hd' => $sVideoUrlHd,
  3552. );
  3553. }
  3554. return $aResult;
  3555. }
  3556. public function getEventFiles($iEventId)
  3557. {
  3558. $CNF = &$this->_oConfig->CNF;
  3559. $aFiles = $this->_oDb->getMedia($CNF['FIELD_FILE'], $iEventId);
  3560. if(empty($aFiles) || !is_array($aFiles))
  3561. return array();
  3562. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_files'));
  3563. $aResult = array();
  3564. foreach($aFiles as $iFileId) {
  3565. $sFileUrl = $oStorage->getFileUrlById($iFileId);
  3566. $aFileFile = $oStorage->getFile($iFileId);
  3567. $aResult[$iFileId] = array(
  3568. 'id' => $iFileId,
  3569. 'src' => $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($aFileFile['file_name'])),
  3570. 'src_medium' => '',
  3571. 'src_orig' => '',
  3572. 'url' => $sFileUrl
  3573. );
  3574. }
  3575. return $aResult;
  3576. }
  3577. /**
  3578. * Protected Methods
  3579. */
  3580. protected function _serviceGetBlockView($iProfileId = 0, $aBrowseParams = array())
  3581. {
  3582. if(empty($iProfileId) && bx_get('profile_id') !== false)
  3583. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  3584. if(empty($iProfileId) && isLogged())
  3585. $iProfileId = bx_get_logged_profile_id();
  3586. $aBrowseParams['owner_id'] = $iProfileId;
  3587. $aBlock = $this->_getBlockView($aBrowseParams);
  3588. if(!empty($aBlock))
  3589. return $aBlock;
  3590. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  3591. }
  3592. protected function _serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $aBrowseParams = array())
  3593. {
  3594. if(empty($sProfileModule))
  3595. return array();
  3596. if(empty($iProfileContentId) && bx_get('id') !== false)
  3597. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  3598. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  3599. if(empty($oProfile))
  3600. return array();
  3601. $aBrowseParams['owner_id'] = $oProfile->id();
  3602. return $this->_getBlockView($aBrowseParams);
  3603. }
  3604. protected function _serviceGetBlockViews($aBrowseParams = array())
  3605. {
  3606. $aParams = $this->_prepareParams($aBrowseParams);
  3607. if(($sType = $this->_oConfig->getUserChoice('type')) !== false)
  3608. $aParams['type'] = $sType;
  3609. $this->_iOwnerId = $aParams['owner_id'];
  3610. return $this->_oTemplate->getViewsBlock($aParams);
  3611. }
  3612. protected function _serviceGetBlockViewHome($aBrowseParams = array())
  3613. {
  3614. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  3615. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_home'), $sRssUrl);
  3616. return $this->_serviceGetBlockViewByType($aBrowseParams);
  3617. }
  3618. protected function _serviceGetBlockViewHot($aBrowseParams = array())
  3619. {
  3620. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  3621. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_hot'), $sRssUrl);
  3622. return $this->_serviceGetBlockViewByType($aBrowseParams);
  3623. }
  3624. protected function _serviceGetBlockViewByType($aBrowseParams = array())
  3625. {
  3626. $aParams = $this->_prepareParams($aBrowseParams);
  3627. $this->_iOwnerId = $aParams['owner_id'];
  3628. return array(
  3629. 'content' => $this->_oTemplate->getViewBlock($aParams)
  3630. );
  3631. }
  3632. protected function _getBlockPost($iProfileId, $aParams = array())
  3633. {
  3634. $this->_iOwnerId = $iProfileId;
  3635. if($this->isAllowedPost() !== true)
  3636. return array();
  3637. return array(
  3638. 'content' => $this->_oTemplate->getPostBlock($this->_iOwnerId, $aParams)
  3639. );
  3640. }
  3641. protected function _getBlockView($aBrowseParams = array())
  3642. {
  3643. if(empty($aBrowseParams['owner_id']))
  3644. return array();
  3645. $aParams = $this->_prepareParams($aBrowseParams);
  3646. if(empty($aParams['per_page']))
  3647. $aParams['per_page'] = $this->_oConfig->getPerPage('profile');
  3648. $this->_iOwnerId = $aParams['owner_id'];
  3649. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  3650. if(!$oProfileOwner)
  3651. return array();
  3652. $mixedResult = $oProfileOwner->checkAllowedProfileView();
  3653. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED) {
  3654. $this->_oTemplate->displayAccessDenied($mixedResult);
  3655. exit;
  3656. }
  3657. $sUserName = $this->getObjectUser($aParams['owner_id'])->getDisplayName();
  3658. $sView = $aParams['view'];
  3659. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_OWNER . '/' . $this->_iOwnerId . '/';
  3660. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  3661. $aMenu = array(
  3662. 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),
  3663. 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)),
  3664. 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')),
  3665. array('id' => $sView . '-get-rss', 'name' => $sView . '-get-rss', 'class' => '', 'link' => $sRssUrl, 'onclick' => '', 'target' => '_blank', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  3666. );
  3667. $sContent = '';
  3668. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view', $this->_iOwnerId, $this->getUserId(), array('override_content' => &$sContent, 'params' => &$aParams, 'menu' => &$aMenu));
  3669. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $sView . '-view-all', 'menu_items' => $aMenu));
  3670. $oMenu->setSelected('', $sView . '-view-all');
  3671. if (!$sContent)
  3672. $sContent = $this->_oTemplate->getViewBlock($aParams);
  3673. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view'), $sRssUrl);
  3674. return array('content' => $sContent, 'menu' => $oMenu);
  3675. }
  3676. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  3677. {
  3678. $CNF = &$this->_oConfig->CNF;
  3679. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  3680. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iId);
  3681. $sText = '';
  3682. if(isset($aContentInfo['content'])){
  3683. $aTmp = unserialize($aContentInfo['content']);
  3684. if(isset($aTmp['text']))
  3685. $sText = $aTmp['text'];
  3686. }
  3687. if(empty($sText) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  3688. $sText = $aContentInfo[$CNF['FIELD_TITLE']];
  3689. if(!empty($CNF['OBJECT_METATAGS']) && !empty($sText)) {
  3690. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  3691. $sText = $oMetatags->metaParse($iId, $sText);
  3692. }
  3693. return array(
  3694. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  3695. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  3696. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  3697. 'url' => $sUrl,
  3698. 'title' => '',
  3699. 'text' => $sText,
  3700. 'links' => $this->getEventLinks($iId),
  3701. 'images' => array(),
  3702. 'images_attach' => $this->getEventImages($iId),
  3703. 'videos' => array(),
  3704. 'videos_attach' => $this->getEventVideos($iId),
  3705. 'files' => array(),
  3706. 'files_attach' => $this->getEventFiles($iId)
  3707. );
  3708. }
  3709. protected function _isAllowedMute($bPerform = false)
  3710. {
  3711. if($this->_iProfileId == 0)
  3712. return false;
  3713. if(isAdmin())
  3714. return true;
  3715. $aCheckResult = checkActionModule($this->_iProfileId, 'mute', $this->getName(), $bPerform);
  3716. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3717. }
  3718. protected function _isAllowedPin($aEvent, $bPerform = false)
  3719. {
  3720. $iUserId = (int)$this->getUserId();
  3721. if($iUserId == 0)
  3722. return false;
  3723. if(isAdmin() || (int)$aEvent['owner_id'] == $iUserId || ((int)$aEvent['owner_id'] == 0 && $this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && (int)$aEvent['object_id'] == $iUserId))
  3724. return true;
  3725. $aCheckResult = checkActionModule($iUserId, 'pin', $this->getName(), $bPerform);
  3726. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false) {
  3727. if (BxDolService::call($oProfileOwner->getModule(), 'check_allowed_module_action_in_profile', array($oProfileOwner->getContentId(), $this->getName(), 'pin')) === CHECK_ACTION_RESULT_ALLOWED) {
  3728. return true;
  3729. }
  3730. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_pin', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3731. }
  3732. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3733. }
  3734. protected function _isAllowedStick($aEvent, $bPerform = false)
  3735. {
  3736. $iUserId = (int)$this->getUserId();
  3737. if($iUserId == 0)
  3738. return false;
  3739. if(isAdmin())
  3740. return true;
  3741. $aCheckResult = checkActionModule($iUserId, 'stick', $this->getName(), $bPerform);
  3742. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3743. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_stick', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3744. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3745. }
  3746. protected function _isAllowedPromote($aEvent, $bPerform = false)
  3747. {
  3748. if(isAdmin())
  3749. return true;
  3750. $iUserId = (int)$this->getUserId();
  3751. if($iUserId == 0)
  3752. return false;
  3753. $aCheckResult = checkActionModule($iUserId, 'promote', $this->getName(), $bPerform);
  3754. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3755. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_promote', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3756. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3757. }
  3758. protected function _addLink(&$oForm)
  3759. {
  3760. $iUserId = $this->getUserId();
  3761. $iEventId = (int)$oForm->getCleanValue('event_id');
  3762. $sLink = rtrim($oForm->getCleanValue('url'), '/');
  3763. $aMatches = array();
  3764. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  3765. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  3766. $aSiteInfo = bx_get_site_info($sLink, array(
  3767. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  3768. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  3769. ));
  3770. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : _t('_Empty');
  3771. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : _t('_Empty');
  3772. $sMediaUrl = '';
  3773. if(!empty($aSiteInfo['thumbnailUrl']))
  3774. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  3775. else if(!empty($aSiteInfo['OGImage']))
  3776. $sMediaUrl = $aSiteInfo['OGImage'];
  3777. $iMediaId = 0;
  3778. $oStorage = null;
  3779. if(!empty($sMediaUrl)) {
  3780. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  3781. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  3782. }
  3783. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  3784. if(!empty($iId)) {
  3785. if(!empty($oStorage) && !empty($iMediaId))
  3786. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  3787. return array(
  3788. 'id' => $iId,
  3789. 'event_id' => $iEventId,
  3790. 'url' => $sLink,
  3791. 'item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId)
  3792. );
  3793. }
  3794. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  3795. }
  3796. protected function _deleteLinks($iId)
  3797. {
  3798. $aLinks = $this->_oDb->getLinks($iId);
  3799. if(empty($aLinks) || !is_array($aLinks))
  3800. return;
  3801. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  3802. foreach($aLinks as $aLink)
  3803. if(!empty($aLink['media_id']))
  3804. $oStorage->deleteFile($aLink['media_id']);
  3805. $this->_oDb->deleteLinks($iId);
  3806. }
  3807. protected function _saveMedia($sType, $iContentId, $aItemIds, $iProfileId = 0, $isAssociateWithContent = false)
  3808. {
  3809. if(empty($iContentId))
  3810. return;
  3811. if(!$isAssociateWithContent)
  3812. $this->_oDb->deleteMedia($sType, $iContentId);
  3813. if(empty($aItemIds) || !is_array($aItemIds))
  3814. return;
  3815. if(empty($iProfileId))
  3816. $iProfileId = $this->_iProfileId;
  3817. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  3818. $aGhostFiles = $oStorage->getGhosts ($iProfileId, !$isAssociateWithContent ? $iContentId : 0, true, $this->_isModerator());
  3819. if(empty($aGhostFiles) || !is_array($aGhostFiles))
  3820. return;
  3821. foreach($aGhostFiles as $aFile) {
  3822. if(is_array($aItemIds) && !in_array($aFile['id'], $aItemIds))
  3823. continue;
  3824. $iFileId = (int)$aFile['id'];
  3825. if($aFile['private'])
  3826. $oStorage->setFilePrivate($iFileId, 1);
  3827. $oStorage->updateGhostsContentId($iFileId, $iProfileId, $iContentId, $this->_isModerator());
  3828. $this->_oDb->saveMedia($sType, $iContentId, $iFileId);
  3829. }
  3830. }
  3831. protected function _deleteMedia($sType, $iContentId)
  3832. {
  3833. $aItems = $this->_oDb->getMedia($sType, $iContentId);
  3834. if(empty($aItems) || !is_array($aItems))
  3835. return;
  3836. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  3837. foreach($aItems as $iItemId)
  3838. $oStorage->deleteFile($iItemId);
  3839. $this->_oDb->deleteMedia($sType, $iContentId);
  3840. }
  3841. protected function _prepareParams($aParams)
  3842. {
  3843. if(empty($aParams['name']))
  3844. $aParams['name'] = '';
  3845. if(empty($aParams['view']))
  3846. $aParams['view'] = BX_TIMELINE_VIEW_DEFAULT;
  3847. if(empty($aParams['type']))
  3848. $aParams['type'] = BX_TIMELINE_TYPE_DEFAULT;
  3849. if(empty($aParams['owner_id']))
  3850. $aParams['owner_id'] = $this->getUserId();
  3851. if(!isset($aParams['start']) || (int)$aParams['start'] < 0)
  3852. $aParams['start'] = 0;
  3853. if(!isset($aParams['per_page']) || (int)$aParams['per_page'] <= 0)
  3854. $aParams['per_page'] = isset($aParams['per_page_default']) && (int)$aParams['per_page_default'] > 0 ? $aParams['per_page_default'] : $this->_oConfig->getPerPage();
  3855. if(empty($aParams['timeline']) || (int)$aParams['timeline'] < 0)
  3856. $aParams['timeline'] = 0;
  3857. if(empty($aParams['filter']))
  3858. $aParams['filter'] = BX_TIMELINE_FILTER_ALL;
  3859. if(empty($aParams['modules']) || !is_array($aParams['modules']))
  3860. $aParams['modules'] = array();
  3861. if(empty($aParams['blink']) || !is_array($aParams['blink']))
  3862. $aParams['blink'] = array();
  3863. $aParams = array_merge($aParams, array(
  3864. 'browse' => 'list',
  3865. 'status' => BX_TIMELINE_STATUS_ACTIVE,
  3866. 'dynamic_mode' => false,
  3867. ));
  3868. return $aParams;
  3869. }
  3870. protected function _prepareParamsGet()
  3871. {
  3872. $aParams = array();
  3873. $aParams['name'] = bx_get('name');
  3874. $aParams['name'] = $aParams['name'] !== false ? bx_process_input($aParams['name'], BX_DATA_TEXT) : '';
  3875. $aParams['view'] = bx_get('view');
  3876. $aParams['view'] = $aParams['view'] !== false ? bx_process_input($aParams['view'], BX_DATA_TEXT) : BX_TIMELINE_VIEW_DEFAULT;
  3877. $aParams['type'] = bx_get('type');
  3878. $aParams['type'] = $aParams['type'] !== false ? bx_process_input($aParams['type'], BX_DATA_TEXT) : BX_TIMELINE_TYPE_DEFAULT;
  3879. $aParams['owner_id'] = bx_get('owner_id');
  3880. $aParams['owner_id'] = $aParams['owner_id'] !== false ? bx_process_input($aParams['owner_id'], BX_DATA_INT) : $this->getUserId();
  3881. $aParams['start'] = bx_get('start');
  3882. $aParams['start'] = $aParams['start'] !== false ? bx_process_input($aParams['start'], BX_DATA_INT) : 0;
  3883. $aParams['per_page'] = bx_get('per_page');
  3884. $aParams['per_page'] = $aParams['per_page'] !== false ? bx_process_input($aParams['per_page'], BX_DATA_INT) : $this->_oConfig->getPerPage();
  3885. $aParams['timeline'] = bx_get('timeline');
  3886. $aParams['timeline'] = $aParams['timeline'] !== false ? bx_process_input($aParams['timeline']) : '';
  3887. $aParams['filter'] = bx_get('filter');
  3888. $aParams['filter'] = $aParams['filter'] !== false ? bx_process_input($aParams['filter'], BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  3889. $aParams['modules'] = bx_get('modules');
  3890. $aParams['modules'] = $aParams['modules'] !== false ? bx_process_input($aParams['modules'], BX_DATA_TEXT) : array();
  3891. $aParams['blink'] = bx_get('blink');
  3892. $aParams['blink'] = $aParams['blink'] !== false ? explode(',', bx_process_input($aParams['blink'], BX_DATA_TEXT)) : array();
  3893. $aParams = array_merge($aParams, array(
  3894. 'browse' => 'list',
  3895. 'status' => BX_TIMELINE_STATUS_ACTIVE,
  3896. 'dynamic_mode' => true,
  3897. ));
  3898. return $aParams;
  3899. }
  3900. protected function _prepareTextForSave($s)
  3901. {
  3902. return bx_process_input($s, BX_DATA_HTML);
  3903. }
  3904. protected function _prepareFormForAutoSubmit(&$oForm, &$aValues)
  3905. {
  3906. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  3907. $oForm->aParams['csrf']['disable'] = true;
  3908. if(!empty($oForm->aParams['db']['submit_name'])) {
  3909. $sSubmitName = $sSubmitValue = false;
  3910. if(is_array($oForm->aParams['db']['submit_name'])) {
  3911. foreach ($oForm->aParams['db']['submit_name'] as $sName) {
  3912. if(isset($oForm->aInputs[$sName])) {
  3913. $sSubmitName = $sName;
  3914. $sSubmitValue = $oForm->aInputs[$sName]['value'];
  3915. break;
  3916. }
  3917. else if(isset($oForm->aInputs['controls']))
  3918. foreach($oForm->aInputs['controls'] as $mixedKey => $mixedInput)
  3919. if(is_numeric($mixedKey) && isset($mixedInput['name']) && $mixedInput['name'] == $sName) {
  3920. $sSubmitName = $sName;
  3921. $sSubmitValue = $mixedInput['value'];
  3922. break 2;
  3923. }
  3924. }
  3925. }
  3926. else {
  3927. $sName = $oForm->aParams['db']['submit_name'];
  3928. if(isset($oForm->aInputs[$sName])) {
  3929. $sSubmitName = $sName;
  3930. $sSubmitValue = $oForm->aInputs[$sName]['value'];
  3931. }
  3932. else if(isset($oForm->aInputs['controls']))
  3933. foreach($oForm->aInputs['controls'] as $mixedKey => $mixedInput)
  3934. if(is_numeric($mixedKey) && isset($mixedInput['name']) && $mixedInput['name'] == $sName) {
  3935. $sSubmitName = $sName;
  3936. $sSubmitValue = $mixedInput['value'];
  3937. break;
  3938. }
  3939. }
  3940. if($sSubmitName && $sSubmitValue)
  3941. $aValues[$sSubmitName] = $sSubmitValue;
  3942. }
  3943. }
  3944. protected function _getFieldValue($sField, $iContentId)
  3945. {
  3946. $CNF = &$this->_oConfig->CNF;
  3947. if(empty($CNF[$sField]))
  3948. return false;
  3949. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  3950. if(empty($aEvent) || empty($aEvent[$CNF[$sField]]))
  3951. return false;
  3952. return $aEvent[$CNF[$sField]];
  3953. }
  3954. /**
  3955. * Returns records for React Jot using OAuth2
  3956. * @param int $iProfileId
  3957. * @param string $sPage
  3958. * @param string $sTab
  3959. * @param int $iStart
  3960. * @param int $iPerPage
  3961. * @return array
  3962. */
  3963. public function serviceGetUserPosts($iProfileId = 0, $sPage = 'home', $sTab = 'hot', $iStart = 0, $iPerPage = 0)
  3964. {
  3965. $iProfileId = (int)$iProfileId ? (int)$iProfileId : bx_get_logged_profile_id();
  3966. if(empty($iProfileId))
  3967. return array(
  3968. 'code' => 1,
  3969. 'result' => array(),
  3970. 'message' => _t('_bx_timeline_txt_msg_no_profile_id'),
  3971. 'page' => $sPage,
  3972. 'tab' => $sTab
  3973. );
  3974. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  3975. $sView = BX_TIMELINE_VIEW_DEFAULT;
  3976. $sFilter = BX_TIMELINE_FILTER_ALL;
  3977. $aModules = array();
  3978. switch($sPage){
  3979. case 'profile':
  3980. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  3981. $sFilter = BX_TIMELINE_FILTER_OWNER;
  3982. break;
  3983. default:
  3984. if ($this -> _oDb -> isModuleByName($sPage))
  3985. $aModules = array($sPage);
  3986. }
  3987. switch($sTab)
  3988. {
  3989. case 'latest':
  3990. $sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  3991. break;
  3992. case 'popular':
  3993. $sType = BX_TIMELINE_TYPE_HOT;
  3994. break;
  3995. case 'feed':
  3996. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  3997. break;
  3998. default:
  3999. if ($this -> _oDb -> isModuleByName($sTab))
  4000. $aModules = array($sTab);
  4001. }
  4002. $aParams = $this->getParams($sView, $sType, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules);
  4003. $aEvents = $this->_oDb->getEvents($aParams);
  4004. $iCount = $this->_oDb->getEvents(array_merge($aParams, array('count' => true)));
  4005. if(empty($aEvents) || !is_array($aEvents))
  4006. return array(
  4007. 'code' => 0,
  4008. 'result' => array(),
  4009. 'message' => _t('_bx_timeline_txt_msg_no_results'),
  4010. 'page' => $sPage,
  4011. 'tab' => $sTab
  4012. );
  4013. $aBrowseParams = array();
  4014. $aItems = array();
  4015. foreach($aEvents as $aEvent) {
  4016. $aResult = $this->_oTemplate->getData($aEvent, $aBrowseParams);
  4017. if($aResult === false)
  4018. continue;
  4019. $oOwnerProfile = BxDolProfile::getInstance($aResult['owner_id']);
  4020. $aFiles = array();
  4021. $aContent = &$aResult['content'];
  4022. if (!empty($aContent['image']))
  4023. $aFiles['images'] = array_values($aContent['images']);
  4024. if (!empty($aContent['images_attach']))
  4025. $aFiles['images'] = array_values($aContent['images_attach']);
  4026. if (!empty($aContent['videos']))
  4027. $aFiles['videos'] = array_values($aContent['videos']);
  4028. else
  4029. if (!empty($aContent['videos_attach']))
  4030. $aFiles['videos'] = array_values($aContent['videos_attach']);
  4031. if (!empty($aContent['files']))
  4032. $aFiles['files'] = array_values($aContent['files']);
  4033. else
  4034. if (!empty($aContent['files_attach']))
  4035. $aFiles['files'] = array_values($aContent['files_attach']);
  4036. $aItems[$aEvent['id']] = array_merge(array(
  4037. 'owner' => array(
  4038. 'icon' => $oOwnerProfile -> getThumb(),
  4039. 'name' => $oOwnerProfile -> getDisplayName(),
  4040. 'url' => $oOwnerProfile -> getUrl()
  4041. ),
  4042. 'sample' => !empty($aResult['sample']) ? _t($aResult['sample']) : _t('_bx_timeline_txt_sample'),
  4043. 'sample_action' => !empty($aResult['sample_action']) ? _t($aResult['sample_action']) : _t('_bx_timeline_txt_added_sample'),
  4044. 'url' => isset($aResult['url']) ? $aResult['url'] : '',
  4045. 'raw' => isset($aContent['raw']) ? strip_tags($aContent['raw']) : '',
  4046. 'text' => isset($aContent['text']) ? strip_tags($aContent['text']) : '',
  4047. 'views' => isset($aResult['views']['count']) ? (int)$aResult['views']['count'] : 0,
  4048. 'votes' => isset($aResult['votes']['count']) ? (int)$aResult['votes']['count'] : 0,
  4049. 'reactions' => isset($aResult['reactions']['count']) ? (int)$aResult['reactions']['count'] : 0,
  4050. 'scores' => isset($aResult['scores']['count']) ? (int)$aResult['scores']['count'] : 0,
  4051. 'reports' => isset($aResult['reports']['count']) ? (int)$aResult['reports']['count'] : 0,
  4052. 'comments' => isset($aResult['comments']['count']) ? (int)$aResult['comments']['count'] : 0,
  4053. 'date' => isset($aResult['date']) ? $aResult['date'] : $aEvent['date'],
  4054. 'type' => stripos($aEvent['type'], 'timeline') !== false ? 'bx_timeline' : $aEvent['type'],
  4055. 'event_type' => $aEvent['type'],
  4056. 'id' => $aEvent['id'],
  4057. 'content' => $aResult['content'],
  4058. 'title' => isset($aResult['title']) ? _t($aResult['title']) : '',
  4059. 'description' => isset($aResult['description']) ? $aResult['description'] : ''
  4060. ), $aFiles);
  4061. }
  4062. return array(
  4063. 'result' => $aItems,
  4064. 'code' => 0,
  4065. 'message' => '',
  4066. 'page' => $sPage,
  4067. 'tab' => $sTab,
  4068. 'total' => $iCount,
  4069. 'start' => (int)$iStart
  4070. );
  4071. }
  4072. }
  4073. /** @} */