BxTimelineModule.php 194 KB

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