BxBaseModGeneralModule.php 193 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027
  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 BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. define('BX_BASE_MOD_GENERAL_STATUS_ACTIVE', 'active');
  12. define('BX_BASE_MOD_GENERAL_STATUS_HIDDEN', 'hidden');
  13. define('BX_BASE_MOD_GENERAL_STATUS_PENDING', 'pending');
  14. bx_import('BxDolAcl');
  15. /**
  16. * Base module class.
  17. */
  18. class BxBaseModGeneralModule extends BxDolModule
  19. {
  20. protected $_bIsApi;
  21. protected $_iProfileId;
  22. protected $_aSearchableNamesExcept;
  23. protected $_aFormParams;
  24. protected $_aBrowsingFiltersKeys;
  25. function __construct(&$aModule)
  26. {
  27. parent::__construct($aModule);
  28. $this->_bIsApi = bx_is_api();
  29. $this->_iProfileId = bx_get_logged_profile_id();
  30. $this->_aSearchableNamesExcept = [];
  31. $this->_aFormParams = array(
  32. 'display' => false,
  33. 'dynamic_mode' => false,
  34. 'ajax_mode' => false,
  35. 'absolute_action_url' => false,
  36. 'visibility_autoselect' => false,
  37. 'context_id' => 0,
  38. 'custom' => array()
  39. );
  40. $this->_aBrowsingFiltersKeys = ['mode'];
  41. }
  42. // ====== ACTIONS METHODS
  43. public function isEntryActive($aContentInfo)
  44. {
  45. $CNF = &$this->_oConfig->CNF;
  46. $iProfileId = bx_get_logged_profile_id();
  47. $bModerator = $this->_isModerator();
  48. $mixedResult = null;
  49. /**
  50. * @hooks
  51. * @hookdef hook-bx_base_general-is_entry_active '{module_name}', 'is_entry_active' - hook to override whether an entry (content) active or not
  52. * - $unit_name - module name
  53. * - $action - equals `is_entry_active`
  54. * - $object_id - not used
  55. * - $sender_id - not used
  56. * - $extra_params - array of additional params with the following array keys:
  57. * - `viewer_id` - [int] viewer profile id
  58. * - `is_moderator` - [boolean] is viewer has moderator status or not
  59. * - `content_info` - [array] content info array as key&value pairs
  60. * - `override_result` - [boolean] by ref, boolean value which determines whether entry (content) active or not, can be overridden in hook processing
  61. * @hook @ref hook-bx_base_general-is_entry_active
  62. */
  63. bx_alert($this->getName(), 'is_entry_active', 0, 0, [
  64. 'viewer_id' => $iProfileId,
  65. 'is_moderator' => $bModerator,
  66. 'content_info' => $aContentInfo,
  67. 'override_result' => &$mixedResult
  68. ]);
  69. if($mixedResult !== null)
  70. return $mixedResult;
  71. if($this->isEntryAuthor($aContentInfo, $iProfileId) || $bModerator)
  72. return true;
  73. if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  74. $iContextProfileId = abs((int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
  75. $oContextProfile = BxDolProfile::getInstance($iContextProfileId);
  76. $aAdmins = bx_srv($oContextProfile->getModule(), 'get_admins_to_manage_content', [$iContextProfileId]);
  77. if(!empty($aAdmins) && in_array($iProfileId, $aAdmins))
  78. return true;
  79. }
  80. if(isset($CNF['FIELD_STATUS']) && $aContentInfo[$CNF['FIELD_STATUS']] != 'active')
  81. return false;
  82. if(isset($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != 'active')
  83. return false;
  84. return true;
  85. }
  86. public function isEntryAuthor($aContentInfo, $iProfileId = 0)
  87. {
  88. $CNF = &$this->_oConfig->CNF;
  89. if(!$iProfileId)
  90. $iProfileId = bx_get_logged_profile_id();
  91. $mixedResult = null;
  92. /**
  93. * @hooks
  94. * @hookdef hook-bx_base_general-is_entry_author '{module_name}', 'is_entry_author' - hook to check if a viewer is an author of viewed entry (content) or not
  95. * - $unit_name - module name
  96. * - $action - equals `is_entry_author`
  97. * - $object_id - not used
  98. * - $sender_id - not used
  99. * - $extra_params - array of additional params with the following array keys:
  100. * - `viewer_id` - [int] viewer profile id
  101. * - `content_info` - [array] content info array as key&value pairs
  102. * - `override_result` - [boolean] by ref, boolean value which determines whether the viewer is an author of viewed entry (content) or not, can be overridden in hook processing
  103. * @hook @ref hook-bx_base_general-is_entry_author
  104. */
  105. bx_alert($this->getName(), 'is_entry_author', 0, 0, [
  106. 'viewer_id' => $iProfileId,
  107. 'content_info' => $aContentInfo,
  108. 'override_result' => &$mixedResult
  109. ]);
  110. if($mixedResult !== null)
  111. return $mixedResult;
  112. return abs($aContentInfo[$CNF['FIELD_AUTHOR']]) == $iProfileId;
  113. }
  114. public function actionUpdateImage($sFiledName, $iContentId, $sValue)
  115. {
  116. $mixedResult = $this->serviceUpdateImage($sFiledName, $iContentId, $sValue);
  117. if($mixedResult !== false)
  118. echo $mixedResult;
  119. }
  120. public function actionUpdateImagePosition($iContentId, $sFiledName, $sH, $sV)
  121. {
  122. // TODO: check permissions
  123. $this->serviceUpdateImagePosition($iContentId, $sFiledName, $sH, $sV);
  124. }
  125. public function actionApprove()
  126. {
  127. $CNF = &$this->_oConfig->CNF;
  128. if(!isset($CNF['FIELD_STATUS_ADMIN']))
  129. return echoJson([]);
  130. $iContentId = (int)bx_get('content_id');
  131. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  132. if(empty($aContentInfo) || !is_array($aContentInfo) || $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != BX_BASE_MOD_GENERAL_STATUS_PENDING)
  133. return echoJson([]);
  134. if(($mixedCheckResult = $this->checkAllowedApprove($aContentInfo)) !== CHECK_ACTION_RESULT_ALLOWED)
  135. return echoJson(['msg' => $mixedCheckResult]);
  136. $oForm = $this->_getApproveForm($iContentId, $aContentInfo);
  137. $oForm->initChecker();
  138. if(!$oForm->isSubmitted() || !$oForm->isValid()) {
  139. $sPopupId = $this->getName() . '_approve_' . $iContentId;
  140. $sPopupTitle = '_sys_manage_popup_approve_title';
  141. if(!empty($CNF['T']['txt_approve_popup_title']))
  142. $sPopupTitle = $CNF['T']['txt_approve_popup_title'];
  143. return echoJson(['popup' => BxTemplFunctions::getInstance()->popupBox($sPopupId, _t($sPopupTitle), $oForm->getCode(true))]);
  144. }
  145. if($oForm->getCleanValue('do_send')) {
  146. $aResult = [];
  147. if($this->_sendApproveMessage($iContentId, $aContentInfo, $oForm))
  148. $aResult = ['msg' => _t('_sys_manage_txt_sent')];
  149. else
  150. $aResult = ['msg' => _t('_sys_manage_err_cannot_perform_action')];
  151. return echoJson($aResult);
  152. }
  153. if($oForm->getCleanValue('do_submit')) {
  154. $aResult = [];
  155. if($this->_oDb->updateEntriesBy([$CNF['FIELD_STATUS_ADMIN'] => BX_BASE_MOD_GENERAL_STATUS_ACTIVE], [$CNF['FIELD_ID'] => $iContentId])) {
  156. $this->checkAllowedApprove($aContentInfo, true);
  157. $this->onApprove($aContentInfo);
  158. /*
  159. * Process metas.
  160. * Note. It's essential to process metas a the very end,
  161. * because all data related to an entry should be already
  162. * processed and are ready to be passed to alert.
  163. */
  164. $this->processMetasAdd($iContentId);
  165. $aResult = ['msg' => _t('_sys_manage_txt_approved'), 'reload' => 1];
  166. }
  167. else
  168. $aResult = ['msg' => _t('_sys_manage_err_cannot_perform_action')];
  169. return echoJson($aResult);
  170. }
  171. }
  172. public function serviceSetStatus($iId, $sValue, $sStatus = '')
  173. {
  174. $CNF = &$this->_oConfig->CNF;
  175. if(!$sStatus && !empty($CNF['FIELD_STATUS_ADMIN']))
  176. $sStatus = $CNF['FIELD_STATUS_ADMIN'];
  177. $aStatuses = [];
  178. if(!empty($CNF['FIELD_STATUS_ADMIN']))
  179. $aStatuses[] = $CNF['FIELD_STATUS_ADMIN'];
  180. if(!empty($CNF['FIELD_STATUS']))
  181. $aStatuses[] = $CNF['FIELD_STATUS'];
  182. if(!in_array($sStatus, $aStatuses))
  183. return false;
  184. if((int)$this->_oDb->updateEntriesBy([$sStatus => $sValue], [$CNF['FIELD_ID'] => $iId]) == 0)
  185. return false;
  186. if($sValue == BX_BASE_MOD_GENERAL_STATUS_ACTIVE)
  187. $this->onPublished($iId);
  188. }
  189. public function actionRss ()
  190. {
  191. $aArgs = func_get_args();
  192. $this->_rss($aArgs);
  193. }
  194. /**
  195. * Attach link
  196. */
  197. public function actionGetAttachLinkForm()
  198. {
  199. $CNF = &$this->_oConfig->CNF;
  200. $iContentId = ($iContentId = bx_get($CNF['FIELD_ATTACH_LINK_CONTENT_ID'])) !== false ? (int)$iContentId : 0;
  201. echo $this->_oTemplate->getAttachLinkForm($iContentId);
  202. }
  203. public function actionSubmitAttachLinkForm()
  204. {
  205. echoJson($this->getFormAttachLink());
  206. }
  207. public function actionAddAttachLink()
  208. {
  209. $CNF = &$this->_oConfig->CNF;
  210. $sUrl = bx_process_input(bx_get($CNF['FIELD_ATTACH_LINK_URL']));
  211. if(empty($sUrl))
  212. return echoJson([]);
  213. $sUrl = htmlspecialchars_decode($sUrl);
  214. $oStreamContext = stream_context_create([
  215. 'http' => [
  216. 'timeout' => getParam('sys_default_socket_timeout'),
  217. ]
  218. ]);
  219. $sHeader = 'Content-Type';
  220. $aHeaders = @get_headers($sUrl, 1, $oStreamContext);
  221. if(!empty($aHeaders) && is_array($aHeaders) && !empty($aHeaders[$sHeader])) {
  222. $mixedContentType = $aHeaders[$sHeader];
  223. if(!is_array($mixedContentType))
  224. $mixedContentType = [$mixedContentType];
  225. foreach($mixedContentType as $sContentType)
  226. if(strpos($sContentType, 'image') !== false)
  227. return echoJson([]);
  228. }
  229. echoJson($this->addAttachLink([
  230. $CNF['FIELD_ATTACH_LINK_CONTENT_ID'] => ($iContentId = bx_get($CNF['FIELD_ATTACH_LINK_CONTENT_ID'])) !== false ? (int)$iContentId : 0,
  231. $CNF['FIELD_ATTACH_LINK_URL'] => $sUrl
  232. ]));
  233. }
  234. public function actionDeleteAttachLink()
  235. {
  236. $CNF = &$this->_oConfig->CNF;
  237. $iUserId = $this->getUserId();
  238. $iLinkId = bx_process_input(bx_get('id'), BX_DATA_INT);
  239. if(empty($iLinkId))
  240. return echoJson([]);
  241. $aLink = $this->_oDb->getLinksBy(['type' => 'id', 'id' => $iLinkId, 'profile_id' => $iUserId]);
  242. if(empty($aLink) || !is_array($aLink))
  243. return echoJson([]);
  244. if(!empty($aLink['media_id']))
  245. BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS'])->deleteFile($aLink['media_id']);
  246. $aResult = [];
  247. if($this->_oDb->deleteLink($iLinkId))
  248. $aResult = ['code' => 0, 'url' => $aLink['url']];
  249. else
  250. $aResult = ['code' => 1, 'message' => _t(!empty($CNF['txt_link_form_err_delete']) ? $CNF['txt_link_form_err_delete'] : $this->getName() . '_form_post_input_link_err_delete')];
  251. echoJson($aResult);
  252. }
  253. /**
  254. * Attach poll
  255. */
  256. public function actionEmbedPoll($iPollId = 0)
  257. {
  258. if(empty($iPollId) && bx_get('poll_id') !== false)
  259. $iPollId = (int)bx_get('poll_id');
  260. $aParams = bx_get_with_prefix('param');
  261. array_walk($aParams, function(&$sValue) {
  262. $sValue = bx_process_input($sValue);
  263. });
  264. $this->_oTemplate->embedPollItem($iPollId, $aParams);
  265. }
  266. public function actionEmbedPolls($iId = 0)
  267. {
  268. list($iContentId, $aContentInfo) = $this->_getContent($iId);
  269. if($iContentId === false)
  270. return;
  271. $aParams = bx_get_with_prefix('param');
  272. array_walk($aParams, function(&$sValue) {
  273. $sValue = bx_process_input($sValue);
  274. });
  275. $this->_oTemplate->embedPollItems($aContentInfo, $aParams);
  276. }
  277. public function actionGetPoll()
  278. {
  279. $iPollId = (int)bx_get('poll_id');
  280. $sView = bx_process_input(bx_get('view'));
  281. $sMethod = 'serviceGetBlockPoll' . bx_gen_method_name($sView);
  282. if(!method_exists($this, $sMethod))
  283. return echoJson(array());
  284. $aBlock = $this->$sMethod($iPollId, true);
  285. if(empty($aBlock) || !is_array($aBlock))
  286. return echoJson(array());
  287. return echoJson(array(
  288. 'content' => $aBlock['content']
  289. ));
  290. }
  291. public function actionDeletePoll()
  292. {
  293. $CNF = &$this->_oConfig->CNF;
  294. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  295. if(empty($iId))
  296. return echoJson([]);
  297. $aResult = [];
  298. if($this->serviceDeletePoll($iId))
  299. $aResult = ['code' => 0];
  300. else
  301. $aResult = ['code' => 1, 'message' => _t($CNF['txt_err_cannot_perform_action'])];
  302. echoJson($aResult);
  303. }
  304. public function actionGetPollForm()
  305. {
  306. echo $this->_oTemplate->getPollForm((int)bx_get('parent_cid'));
  307. }
  308. public function actionSubmitPollForm()
  309. {
  310. echoJson($this->getPollForm((int)bx_get('parent_cid')));
  311. }
  312. public function serviceGetPollForm()
  313. {
  314. if(!$this->_bIsApi)
  315. return false;
  316. $aResult = $this->getPollForm();
  317. if(isset($aResult['code'])) {
  318. if((int)$aResult['code'] == 0) {
  319. return [
  320. 'id' => $aResult['id'],
  321. 'item' => $aResult['item']
  322. ];
  323. }
  324. else
  325. return isset($aResult['message']) ? [bx_api_get_msg($aResult['message'])] : [];
  326. }
  327. else if(isset($aResult['form'])) {
  328. $sModule = $this->getName();
  329. return [bx_api_get_block('form', $aResult['form'], [
  330. 'ext' => [
  331. 'name' => $sModule,
  332. 'request' => ['url' => '/api.php?r=' . $sModule . '/submit_poll_form', 'immutable' => true]
  333. ]
  334. ])];
  335. }
  336. }
  337. public function serviceSubmitPollForm()
  338. {
  339. if(!$this->_bIsApi)
  340. return false;
  341. return $this->serviceGetPollForm();
  342. }
  343. public function serviceDeletePoll($iId)
  344. {
  345. return $this->_oDb->deletePolls([$this->_oConfig->CNF['FIELD_POLL_ID'] => $iId]);
  346. }
  347. public function getPollForm($iParentCid = 0)
  348. {
  349. $CNF = &$this->_oConfig->CNF;
  350. if(empty($CNF['OBJECT_FORM_POLL']))
  351. return ['code' => 1, 'message' => '_sys_txt_error_occured'];
  352. $iProfileId = bx_get_logged_profile_id();
  353. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_POLL'], $CNF['OBJECT_FORM_POLL_DISPLAY_ADD'], $this->_oTemplate);
  354. $oForm->setParentContentId($iParentCid);
  355. $oForm->initChecker();
  356. if($oForm->isSubmittedAndValid()) {
  357. $iId = $oForm->insert();
  358. if($iId)
  359. return ['code' => 0, 'id' => $iId, 'item' => $this->_oTemplate->getPollItem($iId, $iProfileId, [
  360. 'parent_cid' => $iParentCid,
  361. 'manage' => true
  362. ])];
  363. else
  364. return ['code' => 2, 'message' => '_sys_txt_error_entry_creation'];
  365. }
  366. return [
  367. 'form' => $oForm->{'getCode' . ($this->_bIsApi ? 'API' : '')}(),
  368. 'form_id' => $oForm->id
  369. ];
  370. }
  371. public function actionGetCreatePostForm()
  372. {
  373. $sName = $this->_oConfig->getName();
  374. $aParams = bx_process_input(array_intersect_key($_GET, $this->_aFormParams));
  375. $aParams = array_merge($this->_aFormParams, $aParams);
  376. $aParams['context_id'] = (bool)$aParams['context_id'] ? (int)$aParams['context_id'] : false;
  377. $mixedResponse = $this->serviceGetCreatePostForm($aParams);
  378. if(empty($mixedResponse))
  379. return echoJson(array());
  380. else if(is_array($mixedResponse)) {
  381. $mixedResponse['module'] = $sName;
  382. return echoJson($mixedResponse);
  383. }
  384. return echoJson(array(
  385. 'module' => $sName,
  386. 'content' => $mixedResponse
  387. ));
  388. }
  389. public function actionGetNotes()
  390. {
  391. $CNF = &$this->_oConfig->CNF;
  392. if(empty($CNF['OBJECT_NOTES']))
  393. return echoJson([]);
  394. $iContentId = (int)bx_get('content_id');
  395. $oCmtsNotes = BxDolCmts::getObjectInstance($CNF['OBJECT_NOTES'], $iContentId, true, $this->_oTemplate);
  396. $aCmtsNotes = $oCmtsNotes->getCommentsBlock([], ['in_designbox' => false]);
  397. if(empty($aCmtsNotes) || !is_array($aCmtsNotes))
  398. return echoJson([]);
  399. $sPostfix = $iContentId < 0 ? '_rc' : '';
  400. $sPopupId = $this->getName() . '_notes_' . $iContentId;
  401. $sPopupTitle = !empty($CNF['T']['txt_cmts_notes_popup_view_title' . $sPostfix]) ? $CNF['T']['txt_cmts_notes_popup_view_title' . $sPostfix] : '_cmt_nts_popup_view_title' . $sPostfix;
  402. echoJson(['popup' => BxTemplFunctions::getInstance()->popupBox($sPopupId, _t($sPopupTitle), $aCmtsNotes['content'])]);
  403. }
  404. public function actionNested()
  405. {
  406. $sAction = bx_get('a');
  407. $sMethodName = 'subaction' . ucfirst($sAction);
  408. if (!method_exists($this, $sMethodName)) {
  409. return;
  410. }
  411. $this->$sMethodName();
  412. }
  413. public function actionEmbed($iContentId, $sUnitTemplate = '', $sAddCode = '')
  414. {
  415. $oTemplate = BxDolTemplate::getInstance();
  416. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  417. if(empty($aContentInfo))
  418. $oTemplate->getEmbed(false);
  419. if(empty($sUnitTemplate))
  420. $sUnitTemplate = 'unit_gallery.html';
  421. $CNF = &$this->_oConfig->CNF;
  422. if(!empty($CNF['OBJECT_VIEWS'])) {
  423. $oView = BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $iContentId);
  424. if($oView && $oView->isEnabled())
  425. $oView->doView();
  426. }
  427. $oTemplate->getEmbed($this->_oTemplate->unit($aContentInfo, true, $sUnitTemplate, ['embed' => true]) . $sAddCode);
  428. }
  429. public function subactionDelete()
  430. {
  431. header('Content-type: text/html; charset=utf-8');
  432. $iNestedId = (int)bx_get('id');
  433. $sNestedForm = bx_get('s');
  434. $oForm = BxDolForm::getObjectInstance($sNestedForm, $sNestedForm);
  435. if (!$oForm){
  436. echo _t('_sys_request_page_not_found_cpt');
  437. return;
  438. }
  439. $aNested = $this->_oDb->getNestedBy(array('type' => 'id', 'id' => $iNestedId, 'key_name' => $oForm->aParams['db']['key']), $oForm->aParams['db']['table']);
  440. if (empty($aNested)){
  441. echo _t('_sys_request_page_not_found_cpt');
  442. return;
  443. }
  444. $aContentInfo = $this->_oDb->getContentInfoById ($aNested['content_id']);
  445. if (!$aContentInfo){
  446. echo _t('_sys_request_page_not_found_cpt');
  447. return;
  448. }
  449. elseif (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedEdit ($aContentInfo))) {
  450. echo $sMsg;
  451. }
  452. elseif (!$this->_oDb->deleteNestedById($iNestedId, $oForm->aParams['db']['key'], $oForm->aParams['db']['table'])) {
  453. echo _t('_sys_txt_error_occured');
  454. }
  455. else {
  456. echo 'ok';
  457. }
  458. }
  459. /**
  460. * Get possible recipients for start conversation form
  461. */
  462. public function actionAjaxGetProfiles ()
  463. {
  464. $sTerm = bx_get('term');
  465. $a = BxDolService::call('system', 'profiles_search', array($sTerm), 'TemplServiceProfiles');
  466. header('Content-Type:text/javascript; charset=utf-8');
  467. echo(json_encode($a));
  468. }
  469. public function serviceGetProfiles ($sParams)
  470. {
  471. $aOptions = json_decode($sParams, true);
  472. if (!$sParams || !isset($aOptions['term']))
  473. return [];
  474. return BxDolService::call('system', 'profiles_search', array($aOptions['term']), 'TemplServiceProfiles');
  475. }
  476. public function actionGetBrowsingFilters()
  477. {
  478. $aParams = $this->_prepareBrowsingFiltersParamsGet();
  479. $sContent = $this->_oTemplate->getBrowsingFilters($aParams);
  480. if(empty($sContent))
  481. return echoJson([]);
  482. echoJson([
  483. 'code' => 0,
  484. 'popup' => [
  485. 'html' => $sContent,
  486. 'options' => [
  487. 'closeOnOuterClick' => false,
  488. 'removeOnClose' => false,
  489. ]
  490. ],
  491. ]);
  492. }
  493. public function actionApplyBrowsingFilters()
  494. {
  495. $aParams = $this->_prepareBrowsingFiltersParamsGet();
  496. $aBrowseParams = ['mode' => $aParams['mode'], 'empty_message' => true];
  497. unset($aParams['mode']);
  498. $aBrowseParams['params'] = $aParams;
  499. $mixedResult = $this->serviceBrowse($aBrowseParams);
  500. if(empty($mixedResult))
  501. return echoJson([]);
  502. if(is_array($mixedResult) && isset($mixedResult['content']))
  503. $mixedResult = $mixedResult['content'];
  504. return echoJson([
  505. 'code' => 0,
  506. 'content' => $mixedResult,
  507. 'eval' => $this->_oConfig->getJsObject('main') . '.onApplyBrowsingFilter(oData)'
  508. ]);
  509. }
  510. protected function _prepareBrowsingFiltersParamsGet($mParams = false)
  511. {
  512. $aParams = [];
  513. $bParams = !empty($mParams) && is_array($mParams);
  514. foreach($this->_aBrowsingFiltersKeys as $sKey)
  515. if($bParams) {
  516. if(isset($mParams[$sKey]))
  517. $aParams[$sKey] = $mParams[$sKey];
  518. }
  519. else {
  520. if(($sValue = bx_get($sKey)) !== false)
  521. $aParams[$sKey] = $sValue;
  522. }
  523. return $aParams;
  524. }
  525. // ====== SERVICE METHODS
  526. /**
  527. * Checkes whether a content is active by status (status_admin).
  528. *
  529. * @param type $iContentId
  530. * @return boolean
  531. */
  532. public function serviceIsActive($iContentId)
  533. {
  534. $CNF = &$this->_oConfig->CNF;
  535. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  536. if(empty($aContentInfo))
  537. return false;
  538. if(($sKey = 'FIELD_STATUS') && isset($CNF[$sKey]) && $aContentInfo[$CNF[$sKey]] != 'active')
  539. return false;
  540. if(($sKey = 'FIELD_STATUS_ADMIN') && isset($CNF[$sKey]) && isset($aContentInfo[$CNF[$sKey]]) && $aContentInfo[$CNF[$sKey]] != 'active')
  541. return false;
  542. return true;
  543. }
  544. public function serviceIsAllowedAddContentToContext($iContextPid)
  545. {
  546. $oContext = false;
  547. if(!$iContextPid || !($oContext = BxDolProfile::getInstance((int)$iContextPid)))
  548. return false;
  549. if($iContextPid == bx_get_logged_profile_id())
  550. return true;
  551. return bx_srv($oContext->getModule(), 'check_allowed_post_in_profile', [$oContext->getContentId(), $this->getName()]) === CHECK_ACTION_RESULT_ALLOWED;
  552. }
  553. public function serviceIsBadgesAvaliable()
  554. {
  555. if(!isAdmin() && !$this->_isAdministrator())
  556. return false;
  557. $aBadges = BxDolBadges::getInstance()->getData([
  558. 'type' => 'by_module&object',
  559. 'object_id' => 0,
  560. 'module' => $this->getName()
  561. ]);
  562. return count($aBadges) > 0 ? true : false;
  563. }
  564. public function serviceGetSafeServices()
  565. {
  566. return array(
  567. // other
  568. 'ModuleIcon' => '',
  569. 'GetLink' => '',
  570. // browse
  571. 'GetSearchResultUnit' => '',
  572. 'Browse' => '',
  573. 'BrowseFeatured' => '',
  574. 'BrowseFavorite' => '',
  575. // forms
  576. 'GetCreatePostForm' => '',
  577. 'EntityCreate' => '',
  578. 'EntityEdit' => '',
  579. 'EntityDelete' => '',
  580. 'UpdateImage' => '',
  581. //manage
  582. 'GetInfo' => '',
  583. 'EditEntity' => '',
  584. // polls
  585. 'GetPollForm' => '',
  586. 'SubmitPollForm' => '',
  587. 'DeletePoll' => '',
  588. 'GetBlockPollAnswers' => '',
  589. 'GetBlockPollResults' => '',
  590. // page blocks
  591. 'EntityTextBlock' => '',
  592. 'EntityInfo' => '',
  593. 'EntityInfoFull' => '',
  594. 'EntityInfoExtended' => '',
  595. 'EntityLocation' => '',
  596. 'EntityComments' => '',
  597. 'EntityAttachments' => '',
  598. 'CategoriesMultiList' => '',
  599. // menu
  600. 'EntityAllActions' => '',
  601. 'EntityActions' => '',
  602. 'EntitySocialSharing' => '',
  603. 'MyEntriesActions' => '',
  604. 'GetProfiles' => '',
  605. );
  606. }
  607. /**
  608. * @page service Service Calls
  609. * @section bx_base_general Base General
  610. * @subsection bx_base_general-other Other
  611. * @subsubsection bx_base_general-module_icon module_icon
  612. *
  613. * @code bx_srv('bx_posts', 'module_icon', [...]); @endcode
  614. *
  615. * Get module icon as CSS class name with FontAwesome icon name class and color class
  616. *
  617. * @see BxBaseModGeneralModule::serviceModuleIcon
  618. */
  619. /**
  620. * @ref bx_base_general-module_icon "module_icon"
  621. */
  622. public function serviceModuleIcon ()
  623. {
  624. return isset($this->_oConfig->CNF['ICON']) ? $this->_oConfig->CNF['ICON'] : '';
  625. }
  626. /**
  627. * @page service Service Calls
  628. * @section bx_base_general Base General
  629. * @subsection bx_base_general-other Other
  630. * @subsubsection bx_base_general-module_sample module_sample
  631. *
  632. * @code bx_srv('bx_posts', 'module_sample', [...]); @endcode
  633. *
  634. * Get module sample
  635. *
  636. * @see BxBaseModGeneralModule::serviceModuleSample
  637. */
  638. /**
  639. * @ref bx_base_general-module_sample "module_sample"
  640. */
  641. public function serviceModuleSample ()
  642. {
  643. return $this->_oConfig->CNF['T']['txt_sample_single'] ?? '';
  644. }
  645. /**
  646. * @page service Service Calls
  647. * @section bx_base_general Base General
  648. * @subsection bx_base_general-other Other
  649. * @subsubsection bx_base_general-module_sample module_config
  650. *
  651. * @code bx_srv('bx_posts', 'module_config', [...]); @endcode
  652. *
  653. * Get module config (CNF)
  654. *
  655. * @see BxBaseModGeneralModule::serviceModuleConfig
  656. */
  657. /**
  658. * @ref bx_base_general-module_config "module_config"
  659. */
  660. public function serviceModuleConfig ()
  661. {
  662. return $this->_oConfig->getCNF();
  663. }
  664. public function serviceGetModerators($iContentId)
  665. {
  666. return $this->getModerators($iContentId);
  667. }
  668. public function serviceGetAuthor ($iContentId)
  669. {
  670. $mixedResult = $this->_getFieldValue('FIELD_AUTHOR', $iContentId);
  671. return $mixedResult !== false ? (int)$mixedResult : 0;
  672. }
  673. public function serviceGetPrivacyView ($iContentId)
  674. {
  675. return $this->_getFieldValue('FIELD_ALLOW_VIEW_TO', $iContentId);
  676. }
  677. public function serviceGetDateAdded ($iContentId)
  678. {
  679. $mixedResult = $this->_getFieldValue('FIELD_ADDED', $iContentId);
  680. return $mixedResult !== false ? (int)$mixedResult : 0;
  681. }
  682. public function serviceGetDateChanged ($iContentId)
  683. {
  684. $mixedResult = $this->_getFieldValue('FIELD_CHANGED', $iContentId);
  685. return $mixedResult !== false ? (int)$mixedResult : 0;
  686. }
  687. /**
  688. * @page service Service Calls
  689. * @section bx_base_general Base General
  690. * @subsection bx_base_general-other Other
  691. * @subsubsection bx_base_general-get_link_add get_link_add
  692. *
  693. * @code bx_srv('bx_posts', 'get_link_add', [...]); @endcode
  694. *
  695. * Get add entry URL.
  696. *
  697. * @see BxBaseModGeneralModule::serviceGetLinkAdd
  698. */
  699. /**
  700. * @ref bx_base_general-get_link_add "get_link_add"
  701. */
  702. public function serviceGetLinkAdd ()
  703. {
  704. $sUri = $this->_oConfig->getEntryUri('add');
  705. if(!$sUri)
  706. return '';
  707. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $sUri));
  708. }
  709. /**
  710. * @page service Service Calls
  711. * @section bx_base_general Base General
  712. * @subsection bx_base_general-other Other
  713. * @subsubsection bx_base_general-get_link_edit get_link_edit
  714. *
  715. * @code bx_srv('bx_posts', 'get_link_edit', [...]); @endcode
  716. *
  717. * Get edit entry URL for the specified content.
  718. * @param $iContentId content id
  719. *
  720. * @see BxBaseModGeneralModule::serviceGetLinkEdit
  721. */
  722. /**
  723. * @ref bx_base_general-get_link_edit "get_link_edit"
  724. */
  725. public function serviceGetLinkEdit ($iContentId)
  726. {
  727. $CNF = &$this->_oConfig->CNF;
  728. $sUri = $this->_oConfig->getEntryUri('edit');
  729. if(!$sUri)
  730. return '';
  731. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  732. if(empty($aContentInfo))
  733. return '';
  734. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $sUri . '&id=' . $aContentInfo[$CNF['FIELD_ID']]));
  735. }
  736. /**
  737. * @page service Service Calls
  738. * @section bx_base_general Base General
  739. * @subsection bx_base_general-other Other
  740. * @subsubsection bx_base_general-get_link get_link
  741. *
  742. * @code bx_srv('bx_posts', 'get_link', [...]); @endcode
  743. *
  744. * Get URL for the specified content.
  745. * @param $iContentId content id
  746. *
  747. * @see BxBaseModGeneralModule::serviceGetLink
  748. */
  749. /**
  750. * @ref bx_base_general-get_link "get_link"
  751. */
  752. public function serviceGetLink ($iContentId)
  753. {
  754. $CNF = &$this->_oConfig->CNF;
  755. $sUri = $this->_oConfig->getEntryUri('view');
  756. if(!$sUri)
  757. return '';
  758. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  759. if(empty($aContentInfo))
  760. return '';
  761. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $sUri . '&id=' . $aContentInfo[$CNF['FIELD_ID']]));
  762. }
  763. public function serviceGetTitle ($iContentId)
  764. {
  765. $mixedResult = $this->_getFieldValue('FIELD_TITLE', $iContentId);
  766. return $mixedResult !== false ? $mixedResult : '';
  767. }
  768. public function serviceGetText ($iContentId)
  769. {
  770. $mixedResult = $this->_getFieldValue('FIELD_TEXT', $iContentId);
  771. if (false === $mixedResult)
  772. return '';
  773. $CNF = &$this->_oConfig->CNF;
  774. if (!empty($CNF['OBJECT_METATAGS']) && is_string($mixedResult)) {
  775. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  776. $mixedResult = $oMetatags->metaParse($iContentId, $mixedResult);
  777. }
  778. return $mixedResult;
  779. }
  780. public function serviceGetLocation ($iContentId)
  781. {
  782. $CNF = &$this->_oConfig->CNF;
  783. if(empty($CNF['OBJECT_METATAGS']))
  784. return [];
  785. $mixedResult = $this->_getFieldValue('FIELD_LOCATION', $iContentId);
  786. if(false === $mixedResult)
  787. return [];
  788. $oMeta = false;
  789. if(!($oMeta = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS'])) || !$oMeta->locationsIsEnabled())
  790. return false;
  791. $aLocation = $oMeta->locationGet($iContentId);
  792. if(empty($aLocation) || !is_array($aLocation))
  793. return false;
  794. return array_values(array_slice($aLocation, 1));
  795. }
  796. public function serviceGetEmbed ($iContentId)
  797. {
  798. $sTitle = $this->_getFieldValue('FIELD_TITLE', $iContentId);
  799. return $this->_oTemplate->parseHtmlByName('embed.html', [
  800. 'title' => $sTitle,
  801. 'url' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'embed/' . $iContentId . '/'
  802. ]);
  803. }
  804. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  805. {
  806. $CNF = &$this->_oConfig->CNF;
  807. $aContentInfo = $this->_getFields($iContentId);
  808. if(empty($aContentInfo))
  809. return [];
  810. if($bSearchableFieldsOnly === false)
  811. return $aContentInfo;
  812. else if(is_string($bSearchableFieldsOnly) && isset($aContentInfo[$bSearchableFieldsOnly]))
  813. return $aContentInfo[$bSearchableFieldsOnly];
  814. if(($sSf = $CNF['PARAM_SEARCHABLE_FIELDS'] ?? false) && ($aFields = explode(',', getParam($sSf))))
  815. return array_intersect_key($aContentInfo, array_flip($aFields));
  816. return [];
  817. }
  818. public function serviceGetInfoApi ($iContentId, $bExtendedUnits = false)
  819. {
  820. $aData = $this->serviceGetInfo($iContentId, false);
  821. if($aData)
  822. $aData = $this->getDataAPI($aData, ['extended' => $bExtendedUnits]);
  823. return $aData;
  824. }
  825. /**
  826. * @page service Service Calls
  827. * @section bx_base_general Base General
  828. * @subsection bx_base_general-browsing Browsing
  829. * @subsubsection bx_base_general-get_search_result_unit get_search_result_unit
  830. *
  831. * @code bx_srv('bx_posts', 'get_search_result_unit', [3,"unit_gallery.html"]); @endcode
  832. *
  833. * Get browsing unit for the specified content
  834. * @param $iContentId content id
  835. * @param $sUnitTemplate unit template, such as: unit_full.html, unit_gallery.html, unit_live_search.html
  836. *
  837. * @see BxBaseModGeneralModule::serviceGetSearchResultUnit
  838. */
  839. /**
  840. * @ref bx_base_general-get_search_result_unit "get_search_result_unit"
  841. */
  842. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  843. {
  844. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  845. if($this->_bIsApi)
  846. return $this->getDataAPI($aContentInfo);
  847. if(empty($aContentInfo))
  848. return '';
  849. if(empty($sUnitTemplate))
  850. $sUnitTemplate = 'unit.html';
  851. return $this->_oTemplate->unit($aContentInfo, true, $sUnitTemplate);
  852. }
  853. /**
  854. * @page service Service Calls
  855. * @section bx_base_general Base General
  856. * @subsection bx_base_general-browsing Browsing
  857. * @subsubsection bx_base_general-get_view get_view
  858. *
  859. * @code bx_srv('bx_posts', 'get_view', [3]); @endcode
  860. *
  861. * Get view for the specified content
  862. * @param $iContentId content id
  863. *
  864. * @see BxBaseModGeneralModule::serviceGetView
  865. */
  866. /**
  867. * @ref bx_base_general-get_view "get_view"
  868. */
  869. public function serviceGetView ($iContentId)
  870. {
  871. return $this->serviceEntityTextBlock($iContentId);
  872. }
  873. public function serviceGetAll ($aParams = array())
  874. {
  875. if(empty($aParams) || !is_array($aParams))
  876. $aParams = array('type' => 'all');
  877. return $this->_oDb->getEntriesBy($aParams);
  878. }
  879. public function serviceGetAllByAuthor ($iProfileId)
  880. {
  881. return $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  882. }
  883. public function serviceGetSortableFieldsExtended($aInputsAdd = array())
  884. {
  885. $CNF = &$this->_oConfig->CNF;
  886. if(empty($CNF['OBJECT_FORM_ENTRY']))
  887. return array();
  888. $aResult = array();
  889. $aSortableFields = [];
  890. $aDisplays = [];
  891. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'])) {
  892. $aDisplays[] = $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'];
  893. }
  894. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'])) {
  895. $aDisplays[] = $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'];
  896. }
  897. $aInputsAll = BxDolFormQuery::getFormInputs($CNF['OBJECT_FORM_ENTRY']);
  898. foreach($aInputsAll as $aInput){
  899. $aInputsAll[$aInput['name']] = $aInput;
  900. }
  901. $aInputs = BxDolFormQuery::getFormInputs($CNF['OBJECT_FORM_ENTRY'], $aDisplays);
  902. foreach($aInputs as $aInput){
  903. $aInputs[$aInput['name']] = $aInput;
  904. if ($aInput['type'] == 'text'){
  905. $aSortableFields[] = $aInput['name'];
  906. }
  907. }
  908. if(!empty($CNF['FIELD_ADDED']) && isset($aInputsAll[$CNF['FIELD_ADDED']])){
  909. $aSortableFields[] = $CNF['FIELD_ADDED'];
  910. }
  911. if(!empty($CNF['FIELD_CHANGED']) && isset($aInputsAll[$CNF['FIELD_CHANGED']])){
  912. $aSortableFields[] = $CNF['FIELD_CHANGED'];
  913. }
  914. foreach($aSortableFields as $sSortableField){
  915. $aResult[$sSortableField . '_asc'] = [
  916. 'name' => $sSortableField,
  917. 'caption' => $aInputsAll[$sSortableField]['caption'],
  918. 'direction' => 'asc'
  919. ];
  920. $aResult[$sSortableField . '_desc'] = [
  921. 'name' => $sSortableField,
  922. 'caption' => $aInputsAll[$sSortableField]['caption'],
  923. 'direction' => 'desc'
  924. ];
  925. }
  926. /**
  927. * @hooks
  928. * @hookdef hook-bx_base_general-get_sortable_fields '{module_name}', 'get_sortable_fields' - hook to override a list of sortable fields
  929. * - $unit_name - module name
  930. * - $action - equals `get_sortable_fields`
  931. * - $object_id - not used
  932. * - $sender_id - not used
  933. * - $extra_params - array of additional params with the following array keys:
  934. * - `override_result` - [array] a list of searchable fields, can be overridden in hook processing
  935. * @hook @ref hook-bx_base_general-get_sortable_fields
  936. */
  937. bx_alert($this->getName(), 'get_sortable_fields', 0, 0, [
  938. 'extended' => true,
  939. 'override_result' => &$aResult
  940. ]);
  941. return $aResult;
  942. }
  943. public function serviceGetSearchableFieldsExtended($aInputsAdd = array())
  944. {
  945. $CNF = &$this->_oConfig->CNF;
  946. if(empty($CNF['OBJECT_FORM_ENTRY']))
  947. return array();
  948. $aResult = array();
  949. if(!empty($CNF['FIELD_AUTHOR']) && !in_array($CNF['FIELD_AUTHOR'], $this->_aSearchableNamesExcept))
  950. $aResult[$CNF['FIELD_AUTHOR']] = array(
  951. 'type' => 'text_auto',
  952. 'caption' => $CNF['T']['form_field_author'],
  953. 'info' => '',
  954. 'value' => '',
  955. 'values' => '',
  956. 'pass' => ''
  957. );
  958. $aInputs = array();
  959. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'])) {
  960. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  961. $aInputs = array_merge($aInputs, $oForm->aInputs);
  962. }
  963. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'])) {
  964. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'], $this->_oTemplate);
  965. $aInputs = array_merge($aInputs, $oForm->aInputs);
  966. }
  967. if(!empty($aInputsAdd) && is_array($aInputsAdd))
  968. $aInputs = array_merge($aInputs, $aInputsAdd);
  969. if(!empty($CNF['FIELD_LABELS']) && array_key_exists($CNF['FIELD_LABELS'], $aInputs) && !in_array($CNF['FIELD_LABELS'], $this->_aSearchableNamesExcept))
  970. $aResult[$CNF['FIELD_LABELS']] = [
  971. 'type' => 'checkbox_set',
  972. 'caption' => $CNF['T']['form_field_labels'] ?? '_sys_form_input_labels',
  973. 'info' => '',
  974. 'value' => '',
  975. 'values' => '',
  976. 'pass' => '',
  977. 'search_operator' => 'like'
  978. ];
  979. if(($sField = $CNF['FIELD_ALLOW_VIEW_TO'] ?? '') != '' && array_key_exists($sField, $aInputs) && !in_array($sField, $this->_aSearchableNamesExcept))
  980. $aInputs[$sField] = array_merge($aInputs[$sField], [
  981. 'search_type' => 'select',
  982. 'search_operator' => '='
  983. ]);
  984. foreach($aInputs as $aInput){
  985. if(in_array($aInput['type'], BxDolSearchExtended::$SEARCHABLE_TYPES) && !in_array($aInput['name'], $this->_aSearchableNamesExcept)) {
  986. $aField = array(
  987. 'type' => $aInput['type'],
  988. 'caption_system' => $aInput['caption_system_src'],
  989. 'caption' => $aInput['caption_src'],
  990. 'info' => $aInput['info_src'],
  991. 'value' => !empty($aInput['value']) ? $aInput['value'] : '',
  992. 'values' => !empty($aInput['values_src']) ? $aInput['values_src'] : '',
  993. 'pass' => !empty($aInput['db']['pass']) ? $aInput['db']['pass'] : '',
  994. );
  995. if(isset($aInput['search_type']))
  996. $aField['search_type'] = $aInput['search_type'];
  997. if(isset($aInput['search_operator']))
  998. $aField['search_operator'] = $aInput['search_operator'];
  999. $aResult[$aInput['name']] = $aField;
  1000. }
  1001. }
  1002. /**
  1003. * @hooks
  1004. * @hookdef hook-bx_base_general-get_searchable_fields '{module_name}', 'get_searchable_fields' - hook to override a list of searchable fields
  1005. * - $unit_name - module name
  1006. * - $action - equals `get_searchable_fields`
  1007. * - $object_id - not used
  1008. * - $sender_id - not used
  1009. * - $extra_params - array of additional params with the following array keys:
  1010. * - `override_result` - [array] a list of searchable fields, can be overridden in hook processing
  1011. * @hook @ref hook-bx_base_general-get_searchable_fields
  1012. */
  1013. bx_alert($this->getName(), 'get_searchable_fields', 0, 0, [
  1014. 'extended' => true,
  1015. 'override_result' => &$aResult
  1016. ]);
  1017. return $aResult;
  1018. }
  1019. public function serviceGetSearchResultExtended($aParams, $iStart = 0, $iPerPage = 0, $bFilterMode = false)
  1020. {
  1021. if((empty($aParams) || !is_array($aParams)) && !$bFilterMode)
  1022. return array();
  1023. return $this->_oDb->getEntriesBy(array('type' => 'search_ids', 'search_params' => $aParams, 'start' => $iStart, 'per_page' => $iPerPage));
  1024. }
  1025. public function serviceGetSearchableFields ($aInputsAdd = array())
  1026. {
  1027. $CNF = $this->_oConfig->CNF;
  1028. if(!isset($CNF['PARAM_SEARCHABLE_FIELDS']) || !isset($CNF['OBJECT_FORM_ENTRY']) || !isset($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']))
  1029. return array();
  1030. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  1031. if(!$oForm)
  1032. return array();
  1033. $aInputs = $oForm->aInputs;
  1034. if(!empty($aInputsAdd) && is_array($aInputsAdd))
  1035. $aInputs = array_merge($aInputs, $aInputsAdd);
  1036. $aTextTypes = array('text', 'textarea');
  1037. $aTextFields = array();
  1038. foreach($aInputs as $r)
  1039. if(in_array($r['type'], $aTextTypes))
  1040. $aTextFields[$r['name']] = $r['caption'];
  1041. return $aTextFields;
  1042. }
  1043. public function serviceUpdateImage($sFiledName, $iContentId, $sValue)
  1044. {
  1045. $CNF = &$this->_oConfig->CNF;
  1046. $aData = $this->_oDb->getContentInfoById($iContentId);
  1047. if(empty($aData) || !is_array($aData))
  1048. return false;
  1049. if($this->checkAllowedEdit($aData) !== CHECK_ACTION_RESULT_ALLOWED)
  1050. return false;
  1051. // The field name comes from the request (the service is open in API): image fields only.
  1052. if(!in_array($sFiledName, $this->_getUpdateImageFields(), true))
  1053. return false;
  1054. $sValue = (int)$sValue;
  1055. //TODO add transcoder settings
  1056. $oImgStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  1057. if(!$oImgStorage)
  1058. return false;
  1059. $this->_oDb->updateEntriesBy([$sFiledName => $sValue], [$CNF['FIELD_ID'] => $iContentId]);
  1060. $this->serviceUpdateImagePosition($iContentId, $sFiledName, '', '');
  1061. $this->onUpdateImage($iContentId, $sFiledName, $sValue);
  1062. return $this->_bIsApi ? $this->_getUpdateImageUrlApi($sFiledName, $sValue, $oImgStorage) : $oImgStorage->getFileUrlById($sValue);
  1063. }
  1064. /**
  1065. * API: the changed image as the app shows it, a transcoded (display) size instead of the original upload.
  1066. */
  1067. protected function _getUpdateImageUrlApi($sFiledName, $iFileId, $oImgStorage)
  1068. {
  1069. $CNF = &$this->_oConfig->CNF;
  1070. $aTranscoders = [];
  1071. if(!empty($CNF['FIELD_COVER']) && $sFiledName == $CNF['FIELD_COVER']) {
  1072. $aTranscoders = ['OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY'];
  1073. }
  1074. else if(!empty($CNF['FIELD_THUMB']) && $sFiledName == $CNF['FIELD_THUMB']) {
  1075. $aTranscoders = ['OBJECT_IMAGES_TRANSCODER_THUMB', 'OBJECT_IMAGES_TRANSCODER_GALLERY'];
  1076. }
  1077. foreach($aTranscoders as $sKey) {
  1078. if(!empty($CNF[$sKey]) && ($oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF[$sKey])) && ($sUrl = $oTranscoder->getFileUrl($iFileId))) {
  1079. return $sUrl;
  1080. }
  1081. }
  1082. return $oImgStorage->getFileUrlById($iFileId);
  1083. }
  1084. /**
  1085. * Content fields holding a single image, which update_image may change.
  1086. */
  1087. protected function _getUpdateImageFields()
  1088. {
  1089. $CNF = &$this->_oConfig->CNF;
  1090. $aResult = [];
  1091. foreach(['FIELD_THUMB', 'FIELD_COVER', 'FIELD_PICTURE', 'FIELD_BADGE'] as $sKey)
  1092. if(!empty($CNF[$sKey]))
  1093. $aResult[] = $CNF[$sKey];
  1094. return $aResult;
  1095. }
  1096. public function serviceUpdateImagePosition($iContentId, $sFiledName, $sH, $sV)
  1097. {
  1098. $CNF = &$this->_oConfig->CNF;
  1099. $sFieldNamePos = 'FIELD_' . strtoupper($sFiledName) . '_POSITION';
  1100. if(!isset($CNF[$sFieldNamePos]))
  1101. return false;
  1102. $sValue = '';
  1103. if($sH != '' || $sV != '')
  1104. $sValue = json_encode(['x' => $sH, 'y' => $sV]);
  1105. $this->_oDb->updateEntriesBy([$CNF[$sFieldNamePos] => $sValue], [$CNF['FIELD_ID'] => $iContentId]);
  1106. if($this instanceof BxBaseModProfileModule) {
  1107. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1108. bx_content_cache_del_by_prefix('sprofile_unit_vars:' . $aContentInfo['profile_id'] . ':');
  1109. }
  1110. return true;
  1111. }
  1112. public function serviceManageTools($sType = 'common')
  1113. {
  1114. if(!isLogged())
  1115. return '';
  1116. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getGridObject($sType));
  1117. if(!$oGrid)
  1118. return '';
  1119. $CNF = &$this->_oConfig->CNF;
  1120. $mixedMenu = '';
  1121. if(BxDolAcl::getInstance()->isMemberLevelInSet(192)) {
  1122. $oPermalink = BxDolPermalinks::getInstance();
  1123. $aMenuItems = array();
  1124. if(!empty($CNF['OBJECT_GRID_COMMON']) && !empty($CNF['T']['menu_item_manage_my']))
  1125. $aMenuItems[] = array('id' => 'manage-common', 'name' => 'manage-common', 'class' => '', 'link' => $oPermalink->permalink($CNF['URL_MANAGE_COMMON']), 'target' => '_self', 'title' => _t($CNF['T']['menu_item_manage_my']), 'active' => 1);
  1126. if(!empty($CNF['OBJECT_GRID_ADMINISTRATION']) && !empty($CNF['T']['menu_item_manage_all']))
  1127. $aMenuItems[] = array('id' => 'manage-administration', 'name' => 'manage-administration', 'class' => '', 'link' => $oPermalink->permalink($CNF['URL_MANAGE_ADMINISTRATION']), 'target' => '_self', 'title' => _t($CNF['T']['menu_item_manage_all']), 'active' => 1);
  1128. if(count($aMenuItems) > 1) {
  1129. $mixedMenu = new BxTemplMenu(array(
  1130. 'template' => 'menu_block_submenu_ver.html',
  1131. 'menu_items' => $aMenuItems
  1132. ), $this->_oTemplate);
  1133. $mixedMenu->setSelected($this->_aModule['name'], 'manage-' . $sType);
  1134. }
  1135. }
  1136. if(!empty($CNF['OBJECT_MENU_SUBMENU']) && isset($CNF['URI_MANAGE_COMMON']) && ($oSubmenu = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SUBMENU'])) !== false)
  1137. $oSubmenu->setSelected($this->_aModule['name'], $CNF['URI_MANAGE_COMMON']);
  1138. if($this->_bIsApi)
  1139. return [
  1140. 'content' => [bx_api_get_block('grid', $oGrid->getCodeAPI())],
  1141. 'menu' => $mixedMenu ? $mixedMenu->getCodeAPI() : ''
  1142. ];
  1143. $this->_oTemplate->addCss(array('manage_tools.css'));
  1144. $this->_oTemplate->addJs(array('manage_tools.js'));
  1145. $this->_oTemplate->addJsTranslation(array('_sys_grid_search'));
  1146. return array(
  1147. 'content' => $this->_oTemplate->getJsCode('manage_tools', array('sObjNameGrid' => $this->_oConfig->getGridObject($sType))) . $oGrid->getCode(),
  1148. 'menu' => $mixedMenu
  1149. );
  1150. }
  1151. public function serviceGetMenuAddonManageTools()
  1152. {
  1153. return 0;
  1154. }
  1155. public function serviceGetMenuAddonManageToolsProfileStats($iProfileId = 0)
  1156. {
  1157. return 0;
  1158. }
  1159. public function serviceGetObjectBrowse($sMode, $aParams = false, $sClassSearchResult = 'SearchResult')
  1160. {
  1161. if(empty($aParams) || !is_array($aParams))
  1162. $aParams = [];
  1163. return $this->getObjectBrowse($sMode, array_merge(['mode' => $sMode], $aParams), $sClassSearchResult);
  1164. }
  1165. /**
  1166. * @page service Service Calls
  1167. * @section bx_base_general Base General
  1168. * @subsection bx_base_general-browsing Browsing
  1169. * @subsubsection bx_base_general-browse browse
  1170. *
  1171. * @code bx_srv('bx_posts', 'browse', [...]); @endcode
  1172. * @code {{~bx_posts:browse[{"mode":"author", "params":{"author":"10"}}]~}} @endcode
  1173. *
  1174. * Universal browse method.
  1175. * @param $aParams custom browse params, possible params are the following:
  1176. * - mode - browse mode, such as 'recent', 'featured', etc
  1177. * - params - custom params to browse method, for example 'unit_view' can be passed here
  1178. * - design_box - design box style, @see BxBaseFunctions::DesignBoxContent
  1179. * - empty_message - display or not "empty" message when there is no content
  1180. * - ajax_paginate - use AJAX paginate or not
  1181. *
  1182. * @see BxBaseModGeneralModule::serviceBrowse
  1183. */
  1184. /**
  1185. * @ref bx_base_general-browse "browse"
  1186. */
  1187. public function serviceBrowse ($aParams = array())
  1188. {
  1189. if($this->_bIsApi && is_string($aParams)){
  1190. $aParams = json_decode($aParams, true);
  1191. if (isset($aParams['params'])) {
  1192. if(($sK = 'type') && isset($aParams['params'][$sK]))
  1193. $aParams['mode'] = $aParams['params'][$sK];
  1194. if(($sK = 'class_search_result') && isset($aParams['params'][$sK]))
  1195. $aParams[$sK] = $aParams['params'][$sK];
  1196. if(isset($aParams['params']['filters']) && is_array($aParams['params']['filters'])) {
  1197. foreach($aParams['params']['filters'] as $sKey => $sValue) {
  1198. if(in_array($sKey, ['filter', 'condition', 'filters', 'class_search_result'], true))
  1199. continue;
  1200. $aParams['params'][$sKey] = $sValue;
  1201. }
  1202. $aParams['params']['filters'] = [
  1203. 'values' => $aParams['params']['filters']
  1204. ];
  1205. }
  1206. }
  1207. }
  1208. if (isset($aParams['params']['condition']))
  1209. unset($aParams['params']['condition']);
  1210. // **Unsafe on the API.** "filter" lets the caller pick both the column and the operator,
  1211. // so any real column of the module table can be queried, for example status or author.
  1212. // So 'filters' is safe, 'filter' isn't safe!
  1213. if($this->_bIsApi && isset($aParams['params']['filter']))
  1214. unset($aParams['params']['filter']);
  1215. return $this->serviceBrowseWithCondition ($aParams);
  1216. }
  1217. public function serviceBrowseWithCondition ($aParams = array())
  1218. {
  1219. $aDefaults = array (
  1220. 'mode' => 'recent',
  1221. 'params' => false,
  1222. 'design_box' => BX_DB_PADDING_DEF,
  1223. 'empty_message' => false,
  1224. 'ajax_paginate' => true,
  1225. 'class_search_result' => 'SearchResult'
  1226. );
  1227. $aParams = array_merge($aDefaults, $aParams);
  1228. return $this->_serviceBrowse ($aParams['mode'], $aParams['params'], $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate'], $aParams['class_search_result']);
  1229. }
  1230. /**
  1231. * @page service Service Calls
  1232. * @section bx_base_general Base General
  1233. * @subsection bx_base_general-browsing Browsing
  1234. * @subsubsection bx_base_general-browse_featured browse_featured
  1235. *
  1236. * @code bx_srv('bx_posts', 'browse_featured', [...]); @endcode
  1237. *
  1238. * Display featured entries
  1239. * @param $sUnitView browsing unity view,
  1240. * such as: full, extended, gallery, showcase
  1241. * @param $bEmptyMessage display or not "empty" message when there is no content
  1242. * @param $bAjaxPaginate use AJAX paginate or not
  1243. *
  1244. * @see BxBaseModGeneralModule::serviceBrowseFeatured
  1245. */
  1246. /**
  1247. * @ref bx_base_general-browse_featured "browse_featured"
  1248. */
  1249. public function serviceBrowseFeatured ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = true)
  1250. {
  1251. return $this->_serviceBrowse ('featured', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  1252. }
  1253. /**
  1254. * @page service Service Calls
  1255. * @section bx_base_general Base General
  1256. * @subsection bx_base_general-browsing Browsing
  1257. * @subsubsection bx_base_general-browse_favorite browse_favorite
  1258. *
  1259. * @code bx_srv('bx_posts', 'browse_favorite', [...]); @endcode
  1260. *
  1261. * Display entries which were added to favorite list by some member
  1262. * @param $iProfileId profile ID
  1263. * @param $aParams additional browse params, see BxBaseModGeneralModule::serviceBrowse
  1264. *
  1265. * @see BxBaseModGeneralModule::serviceBrowseFavorite BxBaseModGeneralModule::serviceBrowse
  1266. */
  1267. /**
  1268. * @ref bx_base_general-browse_favorite "browse_favorite"
  1269. */
  1270. public function serviceBrowseFavorite ($iProfileId = 0, $aParams = array())
  1271. {
  1272. $CNF = &$this->_oConfig->CNF;
  1273. $oProfile = null;
  1274. if((int)$iProfileId)
  1275. $oProfile = BxDolProfile::getInstance($iProfileId);
  1276. if(!$oProfile && bx_get('profile_id') !== false)
  1277. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  1278. if(!$oProfile)
  1279. $oProfile = BxDolProfile::getInstance();
  1280. if(!$oProfile)
  1281. return '';
  1282. $bEmptyMessage = true;
  1283. if(isset($aParams['empty_message'])) {
  1284. $bEmptyMessage = (bool)$aParams['empty_message'];
  1285. unset($aParams['empty_message']);
  1286. }
  1287. if(bx_get('list_id') !== false && !isset($aParams['list_id']))
  1288. $aParams['list_id'] = (int) bx_get('list_id');
  1289. $aBlock = $this->_serviceBrowse ('favorite', array_merge(array('user' => $oProfile->id()), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage);
  1290. if(!$aBlock)
  1291. return $aBlock;
  1292. $sTitle = _t('_sys_txt_default_favorite_list');
  1293. if(!empty($aParams['list_id']) && ($oFavorite = BxDolFavorite::getObjectInstance($CNF['OBJECT_FAVORITES'], 0, true))) {
  1294. $aList = $oFavorite->getQueryObject()->getList(['type' => 'id', 'list_id' => $aParams['list_id']]);
  1295. if(!empty($aList) && is_array($aList))
  1296. $sTitle = $aList['title'];
  1297. }
  1298. return array_merge($aBlock, ['markers' => [
  1299. 'title' => $sTitle
  1300. ]]);
  1301. }
  1302. /**
  1303. * @page service Service Calls
  1304. * @section bx_base_general Base General
  1305. * @subsection bx_base_general-browsing Browsing
  1306. * @subsubsection bx_base_general-browse_favorite_lists browse_favorite_lists
  1307. *
  1308. * @code bx_srv('bx_posts', 'browse_favorite_lists', [...]); @endcode
  1309. *
  1310. * Display entries which were added to favorite lists grouped by lists by some member
  1311. * @param $iProfileId profile ID
  1312. * @param $aParams additional browse params, see BxBaseModGeneralModule::serviceBrowse
  1313. *
  1314. * @see BxBaseModGeneralModule::serviceBrowseFavoriteLists BxBaseModGeneralModule::serviceBrowse
  1315. */
  1316. /**
  1317. * @ref bx_base_general-browse_favorite_lists "browse_favorite_lists"
  1318. */
  1319. public function serviceBrowseFavoriteLists ($iProfileId = 0, $aParams = array())
  1320. {
  1321. $CNF = &$this->_oConfig->CNF;
  1322. $oProfile = null;
  1323. if((int)$iProfileId)
  1324. $oProfile = BxDolProfile::getInstance($iProfileId);
  1325. if(!$oProfile && bx_get('profile_id') !== false)
  1326. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  1327. if(!$oProfile)
  1328. $oProfile = BxDolProfile::getInstance();
  1329. if(!$oProfile)
  1330. return '';
  1331. $iStart = (bx_get('list_start') !== false ? (int)bx_get('list_start') : 0);
  1332. $iPerPage = (int)getParam($CNF['PARAM_PER_PAGE_FOR_FAVORITES_LISTS']);
  1333. return $this->_oTemplate->getFavoriteList($oProfile, $iStart, $iPerPage, $aParams);
  1334. }
  1335. /**
  1336. * @page service Service Calls
  1337. * @section bx_base_general Base General
  1338. * @subsection bx_base_general-browsing Browsing
  1339. * @subsubsection bx_base_general-browse_by_category category
  1340. *
  1341. * @code bx_srv('bx_posts', 'browse_by_category', [...]); @endcode
  1342. *
  1343. * Display entries in category
  1344. * @param $sUnitView browsing unity view,
  1345. * such as: full, extended, gallery, showcase
  1346. * @param $bEmptyMessage display or not "empty" message when there is no content
  1347. * @param $bAjaxPaginate use AJAX paginate or not
  1348. *
  1349. * @see BxBaseModGeneralModule::serviceBrowseByCategory BxBaseModGeneralModule::serviceBrowse
  1350. */
  1351. /**
  1352. * @ref bx_base_general-browse_by_category "browse_by_category"
  1353. */
  1354. public function serviceBrowseCategory($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $aParams = [])
  1355. {
  1356. $sType = 'category';
  1357. $aParams = array_merge(['category' => bx_process_input(bx_get('category'), BX_DATA_INT)], $aParams);
  1358. if($sUnitView)
  1359. $aParams['unit_view'] = $sUnitView;
  1360. return $this->_serviceBrowse($sType, $aParams, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  1361. }
  1362. /**
  1363. * @page service Service Calls
  1364. * @section bx_base_general Base General
  1365. * @subsection bx_base_general-browsing Browsing
  1366. * @subsubsection bx_base_general-browse_multi_category category
  1367. *
  1368. * @code bx_srv('bx_posts', 'browse_multi_category', [...]); @endcode
  1369. *
  1370. * Display entries in multi category
  1371. * @param $sUnitView browsing unity view,
  1372. * such as: full, extended, gallery, showcase
  1373. * @param $bEmptyMessage display or not "empty" message when there is no content
  1374. * @param $bAjaxPaginate use AJAX paginate or not
  1375. *
  1376. * @see BxBaseModGeneralModule::serviceBrowseMultiCategory BxBaseModGeneralModule::serviceBrowse
  1377. */
  1378. /**
  1379. * @ref bx_base_general-browse_multi_category "browse_multi_category"
  1380. */
  1381. public function serviceBrowseMultiCategory($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $aParams = [])
  1382. {
  1383. $sType = 'multi_category';
  1384. $aParams = array_merge(['category' => bx_process_input(bx_get('category'))], $aParams);
  1385. if($sUnitView)
  1386. $aParams['unit_view'] = $sUnitView;
  1387. return $this->_serviceBrowse($sType, $aParams, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  1388. }
  1389. /**
  1390. * @page service Service Calls
  1391. * @section bx_base_general Base General
  1392. * @subsection bx_base_general-browsing Browsing
  1393. * @subsubsection bx_base_general-browse_favorite_list_actions browse_favorite_list_actions
  1394. *
  1395. * @code bx_srv('bx_posts', 'browse_favorite_list_actions', [...]); @endcode
  1396. *
  1397. * Display menu actions for favorite lists
  1398. *
  1399. * @see BxBaseModGeneralModule::serviceFavoritesListActions
  1400. */
  1401. /**
  1402. * @ref bx_base_general-browse_favorite_list_actions "browse_favorite_list_actions"
  1403. */
  1404. public function serviceFavoritesListActions()
  1405. {
  1406. $iListId = 0;
  1407. if(bx_get('list_id') !== false)
  1408. $iListId = (int) bx_get('list_id');
  1409. $oProfile = null;
  1410. if(bx_get('profile_id') !== false)
  1411. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  1412. if(!$oProfile)
  1413. return false;
  1414. $CNF = &$this->_oConfig->CNF;
  1415. $oFavorite = BxDolFavorite::getObjectInstance($CNF['OBJECT_FAVORITES'], 0, true);
  1416. $aList = $oFavorite->getQueryObject()->getList(array('type' => 'id', 'list_id' => $iListId));
  1417. if($iListId != 0 && (empty($aList) || !is_array($aList)))
  1418. return false;
  1419. $sRv = '';
  1420. if (!empty($aList) && $oFavorite->isAllowedEditList($aList['author_id'])){
  1421. $aMarkers = array(
  1422. 'js_object' => $oFavorite->getJsObjectName(),
  1423. 'list_id' => $iListId,
  1424. );
  1425. $oMenu = BxDolMenu::getObjectInstance('sys_favorite_list');
  1426. $oMenu->addMarkers($aMarkers);
  1427. $sMenu = $oMenu->getCode();
  1428. $sRv .= $sMenu . $oFavorite->getJsScript();
  1429. }
  1430. $aMarkers = array(
  1431. 'id' => $iListId,
  1432. 'module' => $this->_aModule['name'],
  1433. 'url' => $this->_getFavoriteListUrl($iListId, $oProfile->id()),
  1434. 'title' => $iListId > 0 ? $aList['title'] : _t('_sys_txt_default_favorite_list')
  1435. );
  1436. $oMenu = BxDolMenu::getObjectInstance('sys_social_sharing');
  1437. $oMenu->addMarkers($aMarkers);
  1438. $sRv .= $sMenu = $oMenu->getCode();
  1439. return $sRv;
  1440. }
  1441. /**
  1442. * @page service Service Calls
  1443. * @section bx_base_general Base General
  1444. * @subsection bx_base_general-menu Menu
  1445. * @subsubsection bx_base_general-favorites_list_info favorites_list_info
  1446. *
  1447. * @code bx_srv('bx_posts', 'favorites_list_info', [...]); @endcode
  1448. *
  1449. * Favorites list info
  1450. * @param $aParams array with additional custom params
  1451. * which may overwrite some default values
  1452. *
  1453. * @see BxBaseModGeneralModule::serviceFavoritesListInfo
  1454. */
  1455. /**
  1456. * @ref bx_base_general-favorites_list_info "favorites_list_info"
  1457. */
  1458. public function serviceFavoritesListInfo($aParams = array())
  1459. {
  1460. $CNF = &$this->_oConfig->CNF;
  1461. $iListId = 0;
  1462. if(bx_get('list_id') !== false)
  1463. $iListId = (int) bx_get('list_id');
  1464. $oFavorite = BxDolFavorite::getObjectInstance($CNF['OBJECT_FAVORITES'], 0, true);
  1465. $aList = $oFavorite->getQueryObject()->getList(array('type' => 'id', 'list_id' => $iListId));
  1466. if($iListId != 0 && (empty($aList) || !is_array($aList)))
  1467. return false;
  1468. $oProfile = null;
  1469. if(bx_get('profile_id') !== false)
  1470. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  1471. if(!$oProfile)
  1472. return false;
  1473. return $this->_oTemplate->getFavoritesListInfo($aList, $oProfile);
  1474. }
  1475. /**
  1476. * Display entries posted into particular context
  1477. * @return HTML string
  1478. */
  1479. public function serviceBrowseContext ($iProfileId = 0, $aParams = array())
  1480. {
  1481. return $this->_serviceBrowseWithParam ('context', 'profile_id', $iProfileId, $aParams);
  1482. }
  1483. public function serviceBrowseFollowedContexts ($iProfileId = 0, $aParams = [])
  1484. {
  1485. return $this->_serviceBrowseWithParam ('followed_contexts', 'profile_id', $iProfileId, $aParams);
  1486. }
  1487. public function _serviceBrowseWithParam ($sParamName, $sParamGet, $sParamVal, $aParams = array())
  1488. {
  1489. if(!$sParamVal)
  1490. $sParamVal = bx_process_input(bx_get($sParamGet), BX_DATA_INT);
  1491. if(!$sParamVal)
  1492. return '';
  1493. $bEmptyMessage = true;
  1494. if(isset($aParams['empty_message'])) {
  1495. $bEmptyMessage = (bool)$aParams['empty_message'];
  1496. unset($aParams['empty_message']);
  1497. }
  1498. $bAjaxPaginate = true;
  1499. if(isset($aParams['ajax_paginate'])) {
  1500. $bAjaxPaginate = (bool)$aParams['ajax_paginate'];
  1501. unset($aParams['ajax_paginate']);
  1502. }
  1503. return $this->_serviceBrowse ($sParamName, array_merge(array($sParamName => $sParamVal), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  1504. }
  1505. public function getFormsHelper ()
  1506. {
  1507. $sClass = 'FormsEntryHelper';
  1508. $oObject = null;
  1509. bx_alert('system', 'get_forms_helper', 0, 0, [
  1510. 'module' => $this->getName(),
  1511. 'class' => &$sClass,
  1512. 'class_ref' => &$sClass,
  1513. 'object' => &$oObject
  1514. ]);
  1515. if($oObject !== null)
  1516. return $oObject;
  1517. bx_import($sClass, $this->_aModule);
  1518. $sClass = $this->_aModule['class_prefix'] . $sClass;
  1519. return new $sClass($this);
  1520. }
  1521. public function serviceFormsHelper()
  1522. {
  1523. return $this->getFormsHelper();
  1524. }
  1525. /**
  1526. * Add entry using provided fields' values.
  1527. * @return array with result:
  1528. * 'code' is 0 on success or non-zero on error,
  1529. * 'message' is error message in case of error,
  1530. * 'content' is content info array in case of success
  1531. */
  1532. public function serviceEntityAdd($iProfile, $aValues, $sDisplay = false)
  1533. {
  1534. $oFormsHelper = $this->getFormsHelper();
  1535. return $oFormsHelper->addData($iProfile, $aValues, $sDisplay);
  1536. }
  1537. public function serviceEntityAddForcedly($iProfile, $aValues, $sDisplay = false)
  1538. {
  1539. $oFormsHelper = $this->getFormsHelper();
  1540. $oFormsHelper->setValidMode(true);
  1541. return $oFormsHelper->addData($iProfile, $aValues, $sDisplay);
  1542. }
  1543. /**
  1544. * Perform redirect after content creation
  1545. * @return nothing, rediret header is sent
  1546. */
  1547. public function serviceRedirectAfterAdd($aContentInfo)
  1548. {
  1549. $oFormsHelper = $this->getFormsHelper();
  1550. $oFormsHelper->redirectAfterAdd($aContentInfo);
  1551. }
  1552. /**
  1553. * Get form object for add, edit, view or delete the content
  1554. * @param $sType 'add', 'edit', 'view' or 'delete'
  1555. * @param $aParams optional array with parameters(display name, etc)
  1556. * @return form object or false on error
  1557. */
  1558. public function serviceGetObjectForm ($sType, $aParams = array())
  1559. {
  1560. if(!in_array($sType, array('add', 'edit', 'view', 'delete')))
  1561. return false;
  1562. $iLoggedId = (int)bx_get_logged_profile_id();
  1563. $mixedContextId = isset($aParams['context_id']) ? $aParams['context_id'] : false;
  1564. $oContextProfile = false;
  1565. $bContext = $mixedContextId !== false;
  1566. if($bContext) {
  1567. $oContextProfile = BxDolProfile::getInstance(abs($mixedContextId));
  1568. $bContext = $oContextProfile !== false;
  1569. if($bContext && $oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  1570. return false;
  1571. }
  1572. $CNF = &$this->_oConfig->CNF;
  1573. $oFormsHelper = $this->getFormsHelper();
  1574. $sParamsKey = 'ajax_mode';
  1575. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  1576. $oFormsHelper->setAjaxMode((bool)$aParams[$sParamsKey]);
  1577. $sParamsKey = 'absolute_action_url';
  1578. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  1579. $oFormsHelper->setAbsoluteActionUrl((bool)$aParams[$sParamsKey]);
  1580. if($bContext)
  1581. $oFormsHelper->setContextId($mixedContextId);
  1582. $sDisplay = !empty($aParams['display']) ? $aParams['display'] : false;
  1583. $sFunc = 'getObjectForm' . ucfirst($sType);
  1584. $oForm = $oFormsHelper->$sFunc($sDisplay);
  1585. $sParamsKey = 'visibility_auto';
  1586. if((!isset($aParams[$sParamsKey]) || (bool)$aParams[$sParamsKey] === true) && ($sField = $CNF['FIELD_ALLOW_VIEW_TO'] ?? false) && !empty($oForm->aInputs[$sField]) && (!$bContext || $mixedContextId < 0)) {
  1587. $bContextOwner = $bContext && abs($mixedContextId) == $iLoggedId;
  1588. if(!$bContext || $bContextOwner) {
  1589. $iGc = 0;
  1590. $iKeyGh = false;
  1591. foreach($oForm->aInputs[$sField]['values'] as $iKey => $aValue) {
  1592. //--- Remove empty items grouping elements (group_header and group_end w/o subitems).
  1593. if(isset($aValue['type']) && in_array($aValue['type'], array('group_header', 'group_end'))) {
  1594. if($iKeyGh !== false && $iGc == 0) {
  1595. unset($oForm->aInputs[$sField]['values'][$iKeyGh]);
  1596. $iKeyGh = false;
  1597. if($aValue['type'] == 'group_end')
  1598. unset($oForm->aInputs[$sField]['values'][$iKey]);
  1599. }
  1600. if($aValue['type'] == 'group_header') {
  1601. $iGc = 0;
  1602. $iKeyGh = $iKey;
  1603. }
  1604. continue;
  1605. }
  1606. //--- Show 'Public' privacy group only in Public post form.
  1607. if(!$bContext && $aValue['key'] == BX_DOL_PG_ALL) {
  1608. $iGc += 1;
  1609. continue;
  1610. }
  1611. //--- Show a default privacy groups in Profile (for Owner) post form.
  1612. if($bContextOwner && ((int)$aValue['key'] >= 0 || $mixedContextId == $aValue['key'])) {
  1613. $iGc += 1;
  1614. continue;
  1615. }
  1616. unset($oForm->aInputs[$sField]['values'][$iKey]);
  1617. }
  1618. }
  1619. else {
  1620. $oForm->aInputs[$sField]['value'] = $mixedContextId;
  1621. $oForm->aInputs[$sField]['type'] = 'hidden';
  1622. }
  1623. }
  1624. $sKey = 'FIELD_LABELS';
  1625. if(!empty($CNF[$sKey]) && !empty($oForm->aInputs[$CNF[$sKey]]) && empty($oForm->aInputs[$CNF[$sKey]]['value']) && $bContext) {
  1626. $iContextProfileId = $oContextProfile->id();
  1627. $sContextModule = $oContextProfile->getModule();
  1628. if(bx_srv($sContextModule, 'is_fan', [$iContextProfileId, $iLoggedId])) {
  1629. $aContextInfo = bx_srv($sContextModule, 'get_content_info_by_profile_id', [$iContextProfileId]);
  1630. if(!empty($aContextInfo['hashtag']))
  1631. $oForm->aInputs[$CNF[$sKey]]['value'] = [$aContextInfo['hashtag']];
  1632. }
  1633. }
  1634. /**
  1635. * @hooks
  1636. * @hookdef hook-system-get_object_form 'system', 'get_object_form' - hook to override an object of create content form, @see BxDolForm
  1637. * - $unit_name - equals `system`
  1638. * - $action - equals `get_object_form`
  1639. * - $object_id - not used
  1640. * - $sender_id - not used
  1641. * - $extra_params - array of additional params with the following array keys:
  1642. * - `module` - [string] module name
  1643. * - `type` - [string] 'add', 'edit', 'view' or 'delete' form display type
  1644. * - `params` - [array] form params array as key&value pairs
  1645. * - `form` - [object] by ref, an object of create content form, @see BxDolForm, can be overridden in hook processing
  1646. * @hook @ref hook-system-get_object_form
  1647. */
  1648. bx_alert('system', 'get_object_form', 0, 0, [
  1649. 'module' => $this->_oConfig->getName(),
  1650. 'type' => $sType,
  1651. 'params' => $aParams,
  1652. 'form' => &$oForm
  1653. ]);
  1654. return $oForm;
  1655. }
  1656. /**
  1657. *
  1658. *
  1659. * Create entry form
  1660. * @return HTML string
  1661. */
  1662. public function serviceEntityCreate ($sParams = false)
  1663. {
  1664. if($this->_bIsApi && ($aParams = bx_api_get_browse_params($sParams))) {
  1665. if(($aKeys = ['context_pid', 'context_nid', 'context_usage']) && ($aParamsContext = array_intersect_key($aParams, array_flip($aKeys)))) {
  1666. $_GET = array_merge($_GET, $aParamsContext);
  1667. $sParams = array_diff_key($aParams, array_flip($aKeys));
  1668. }
  1669. }
  1670. $bParamsArray = is_array($sParams);
  1671. $sDisplay = is_string($sParams) ? $sParams : false;
  1672. if($bParamsArray && !empty($sParams['display']))
  1673. $sDisplay = $sParams['display'];
  1674. $oFormsHelper = $this->getFormsHelper();
  1675. if($bParamsArray && isset($sParams['dynamic_mode']))
  1676. $oFormsHelper->setDynamicMode($sParams['dynamic_mode']);
  1677. $mixedResult = $oFormsHelper->addDataForm($sDisplay);
  1678. if($this->_bIsApi)
  1679. return $mixedResult;
  1680. if(isset($mixedResult['_dt']) && $mixedResult['_dt'] == 'json') {
  1681. echoJson($mixedResult);
  1682. exit;
  1683. }
  1684. return $mixedResult;
  1685. }
  1686. /**
  1687. * @page service Service Calls
  1688. * @section bx_base_general Base General
  1689. * @subsection bx_base_general-forms Forms
  1690. * @subsubsection bx_base_general-get_create_post_form get_create_post_form
  1691. *
  1692. * @code bx_srv('bx_posts', 'get_create_post_form'); @endcode
  1693. *
  1694. * Get content creation form
  1695. * @param $aParams additional parameters array:
  1696. * context_id, ajax_mode, absolute_action_url, displays
  1697. *
  1698. * @see BxBaseModGeneralModule::serviceGetCreatePostForm
  1699. */
  1700. /**
  1701. * @ref bx_base_general-get_create_post_form "get_create_post_form"
  1702. */
  1703. public function serviceGetCreatePostForm($aParams = [])
  1704. {
  1705. $aParams = array_merge($this->_aFormParams, $aParams);
  1706. if($aParams['context_id'] !== false && ($aContextInfo = BxDolProfileQuery::getInstance()->getInfoById(abs($aParams['context_id']))))
  1707. if(bx_srv($aContextInfo['type'], 'check_allowed_post_in_profile', [$aContextInfo['content_id'], $this->getName()]) !== CHECK_ACTION_RESULT_ALLOWED)
  1708. return '';
  1709. $oForm = $this->serviceGetObjectForm('add', $aParams);
  1710. if(!$oForm)
  1711. return '';
  1712. return $this->serviceEntityCreate($aParams);
  1713. }
  1714. /**
  1715. * @page service Service Calls
  1716. * @section bx_base_general Base General
  1717. * @subsection bx_base_general-forms Forms
  1718. * @subsubsection bx_base_general-entity_edit entity_edit
  1719. *
  1720. * @code bx_srv('bx_posts', 'entity_edit', [...]); @endcode
  1721. *
  1722. * Get content edit form
  1723. * @param $iContentId content ID
  1724. * @param $sDisplay optional form display name
  1725. *
  1726. * @see BxBaseModGeneralModule::serviceEntityEdit
  1727. */
  1728. /**
  1729. * @ref bx_base_general-entity_edit "entity_edit"
  1730. */
  1731. public function serviceEntityEdit ($iContentId = 0, $sDisplay = false)
  1732. {
  1733. return $this->_serviceEntityForm ('editDataForm', $iContentId, $sDisplay);
  1734. }
  1735. /**
  1736. * @page service Service Calls
  1737. * @section bx_base_general Base General
  1738. * @subsection bx_base_general-forms Forms
  1739. * @subsubsection bx_base_general-entity_delete entity_delete
  1740. *
  1741. * @code bx_srv('bx_posts', 'entity_delete', [...]); @endcode
  1742. *
  1743. * Get content delete form
  1744. * @param $iContentId content ID
  1745. *
  1746. * @see BxBaseModGeneralModule::serviceEntityDelete
  1747. */
  1748. /**
  1749. * @ref bx_base_general-entity_delete "entity_delete"
  1750. */
  1751. public function serviceEntityDelete ($iContentId = 0)
  1752. {
  1753. $mixedResult = $this->_serviceEntityForm ('deleteDataForm', $iContentId);
  1754. if(!bx_is_api())
  1755. return $mixedResult;
  1756. $aResult = [];
  1757. if(is_a($mixedResult, 'BxTemplFormView')){
  1758. $iContentId = $this->_getContent($iContentId, false);
  1759. $aResult = bx_api_get_block('form', $mixedResult->getCodeAPI(), ['ext' => ['name' => $this->getName(), 'request' => ['url' => '/api.php?r=' . $this->_aModule['name'] . '/entity_delete&params[]=' . $iContentId . '&params[]=' . $mixedResult->aParams['display'], 'immutable' => true]]]);
  1760. }
  1761. else
  1762. $aResult = $mixedResult;
  1763. return [
  1764. $aResult
  1765. ];
  1766. }
  1767. /**
  1768. * @page service Service Calls
  1769. * @section bx_base_general Base General
  1770. * @subsection bx_base_general-page_blocks Page Blocks
  1771. * @subsubsection bx_base_general-entity_text_block entity_text_block
  1772. *
  1773. * @code bx_srv('bx_posts', 'entity_text_block', [...]); @endcode
  1774. *
  1775. * Get content text/description
  1776. * @param $iContentId content ID
  1777. *
  1778. * @see BxBaseModGeneralModule::serviceEntityTextBlock
  1779. */
  1780. /**
  1781. * @ref bx_base_general-entity_text_block "entity_text_block"
  1782. */
  1783. public function serviceEntityTextBlock ($iContentId = 0)
  1784. {
  1785. return $this->_serviceEntityForm ('viewDataEntry', $iContentId);
  1786. }
  1787. /**
  1788. * @page service Service Calls
  1789. * @section bx_base_general Base General
  1790. * @subsection bx_base_general-page_blocks Page Blocks
  1791. * @subsubsection bx_base_general-entity_info entity_info
  1792. *
  1793. * @code bx_srv('bx_posts', 'entity_info', [...]); @endcode
  1794. *
  1795. * Get content info
  1796. * @param $iContentId content ID
  1797. *
  1798. * @see BxBaseModGeneralModule::serviceEntityInfo
  1799. */
  1800. /**
  1801. * @ref bx_base_general-entity_info "entity_info"
  1802. */
  1803. public function serviceEntityInfo ($iContentId = 0, $sDisplay = false)
  1804. {
  1805. return $this->_serviceEntityForm ('viewDataForm', $iContentId, $sDisplay);
  1806. }
  1807. /**
  1808. * @page service Service Calls
  1809. * @section bx_base_general Base General
  1810. * @subsection bx_base_general-page_blocks Page Blocks
  1811. * @subsubsection bx_base_general-entity_info_full entity_info_full
  1812. *
  1813. * @code bx_srv('bx_posts', 'entity_info_full', [...]); @endcode
  1814. *
  1815. * Get full content info
  1816. * @param $iContentId content ID
  1817. *
  1818. * @see BxBaseModGeneralModule::serviceEntityInfoFull
  1819. */
  1820. /**
  1821. * @ref bx_base_general-entity_info_full "entity_info_full"
  1822. */
  1823. public function serviceEntityInfoFull ($iContentId = 0)
  1824. {
  1825. $CNF = &$this->_oConfig->CNF;
  1826. $sDisplayName = 'OBJECT_FORM_ENTRY_DISPLAY_VIEW_FULL';
  1827. return $this->_serviceEntityForm ('viewDataForm', $iContentId, !empty($CNF[$sDisplayName]) ? $CNF[$sDisplayName] : false);
  1828. }
  1829. /**
  1830. * @page service Service Calls
  1831. * @section bx_base_general Base General
  1832. * @subsection bx_base_general-page_blocks Page Blocks
  1833. * @subsubsection bx_base_general-entity_info_extended entity_info_extended
  1834. *
  1835. * @code bx_srv('bx_posts', 'entity_info_extended', [...]); @endcode
  1836. *
  1837. * Get extended content info
  1838. * @param $iContentId content ID
  1839. *
  1840. * @see BxBaseModGeneralModule::serviceEntityInfoExtended
  1841. */
  1842. /**
  1843. * @ref bx_base_general-entity_info_extended "entity_info_extended"
  1844. */
  1845. public function serviceEntityInfoExtended ($iContentId = 0)
  1846. {
  1847. return $this->_serviceTemplateFunc ('entryInfo', $iContentId);
  1848. }
  1849. /**
  1850. * @page service Service Calls
  1851. * @section bx_base_general Base General
  1852. * @subsection bx_base_general-page_blocks Page Blocks
  1853. * @subsubsection bx_base_general-entity_location entity_location
  1854. *
  1855. * @code bx_srv('bx_posts', 'entity_location', [...]); @endcode
  1856. *
  1857. * Get content location
  1858. * @param $iContentId content ID
  1859. *
  1860. * @see BxBaseModGeneralModule::serviceEntityLocation
  1861. */
  1862. /**
  1863. * @ref bx_base_general-entity_location "entity_location"
  1864. */
  1865. public function serviceEntityLocation ($iContentId = 0)
  1866. {
  1867. $CNF = &$this->_oConfig->CNF;
  1868. $mixedContent = $this->_getContent($iContentId);
  1869. if($mixedContent === false)
  1870. return false;
  1871. list($iContentId, $aContentInfo) = $mixedContent;
  1872. $oFormsHelper = $this->getFormsHelper();
  1873. $oFormView = $oFormsHelper->getObjectFormView();
  1874. if(!$oFormView)
  1875. return false;
  1876. $oFormView->initChecker($aContentInfo);
  1877. if(empty($CNF['FIELD_LOCATION']) || !$oFormView->isInputVisible($CNF['FIELD_LOCATION']))
  1878. return false;
  1879. return $this->_oTemplate->entryLocation ($iContentId);
  1880. }
  1881. /**
  1882. * @page service Service Calls
  1883. * @section bx_base_general Base General
  1884. * @subsection bx_base_general-page_blocks Page Blocks
  1885. * @subsubsection bx_base_general-entity_comments entity_comments
  1886. *
  1887. * @code bx_srv('bx_posts', 'entity_comments', [...]); @endcode
  1888. *
  1889. * Get content comments
  1890. * @param $iContentId content ID
  1891. *
  1892. * @see BxBaseModGeneralModule::serviceEntityComments
  1893. */
  1894. /**
  1895. * @ref bx_base_general-entity_comments "entity_comments"
  1896. */
  1897. public function serviceEntityComments ($iContentId = 0)
  1898. {
  1899. $CNF = &$this->_oConfig->CNF;
  1900. if(empty($CNF['OBJECT_COMMENTS']))
  1901. return '';
  1902. return $this->_entityComments($CNF['OBJECT_COMMENTS'], $iContentId);
  1903. }
  1904. /**
  1905. * @page service Service Calls
  1906. * @section bx_base_general Base General
  1907. * @subsection bx_base_general-page_blocks Page Blocks
  1908. * @subsubsection bx_base_general-entity_attachments entity_attachments
  1909. *
  1910. * @code bx_srv('bx_posts', 'entity_attachments', [...]); @endcode
  1911. *
  1912. * Get content attachments
  1913. * @param $iContentId content ID
  1914. *
  1915. * @see BxBaseModGeneralModule::serviceEntityAttachments
  1916. */
  1917. /**
  1918. * @ref bx_base_general-entity_attachments "entity_attachments"
  1919. */
  1920. public function serviceEntityAttachments ($iContentId = 0)
  1921. {
  1922. return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
  1923. }
  1924. /**
  1925. * @page service Service Calls
  1926. * @section bx_base_general Base General
  1927. * @subsection bx_base_general-page_blocks Page Blocks
  1928. * @subsubsection bx_base_general-entity_polls entity_polls
  1929. *
  1930. * @code bx_srv('bx_posts', 'entity_polls', [...]); @endcode
  1931. *
  1932. * Display polls for the specified post
  1933. * @param $iContentId content ID
  1934. *
  1935. * @see BxBaseModGeneralModule::serviceEntityPolls
  1936. */
  1937. /**
  1938. * @ref bx_base_general-entity_polls "entity_polls"
  1939. */
  1940. public function serviceEntityPolls ($iContentId = 0)
  1941. {
  1942. return $this->_serviceTemplateFunc ('entryPolls', $iContentId);
  1943. }
  1944. /**
  1945. * Delete content entry
  1946. * @param $iContentId content id
  1947. * @return error message or empty string on success
  1948. */
  1949. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  1950. {
  1951. $oFormsHelper = $this->getFormsHelper();
  1952. return $oFormsHelper->$sFuncDelete($iContentId);
  1953. }
  1954. /**
  1955. * Edit content entry
  1956. * @param $iContentId content id
  1957. * @param $aValues key value pairs to update
  1958. * @return error message or empty string on success
  1959. */
  1960. public function serviceEditEntity ($iContentId, $aValues, $sDisplay = false)
  1961. {
  1962. if($this->_bIsApi && is_string($aValues))
  1963. $aValues = bx_api_get_browse_params($aValues);
  1964. $oFormsHelper = $this->getFormsHelper();
  1965. return $oFormsHelper->editData($iContentId, $aValues, $sDisplay);
  1966. }
  1967. /**
  1968. * @page service Service Calls
  1969. * @section bx_base_general Base General
  1970. * @subsection bx_base_general-menu Menu
  1971. * @subsubsection bx_base_general-my_entries_actions my_entries_actions
  1972. *
  1973. * @code bx_srv('bx_posts', 'my_entries_actions', [...]); @endcode
  1974. *
  1975. * My entries actions menu
  1976. * @param $iProfileId profiles ID,
  1977. * if omitted it try to get it from 'profile_id' GET param
  1978. *
  1979. * @see BxBaseModGeneralModule::serviceMyEntriesActions
  1980. */
  1981. /**
  1982. * @ref bx_base_general-my_entries_actions "my_entries_actions"
  1983. */
  1984. public function serviceMyEntriesActions ($iProfileId = 0)
  1985. {
  1986. $CNF = &$this->_oConfig->CNF;
  1987. if(empty($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']))
  1988. return false;
  1989. if (!$iProfileId)
  1990. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  1991. if (!$iProfileId || !($oProfile = BxDolProfile::getInstance($iProfileId)))
  1992. return false;
  1993. if ($iProfileId != $this->_iProfileId)
  1994. return false;
  1995. $oMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']);
  1996. return $oMenu ? $oMenu->getCode() : false;
  1997. }
  1998. /**
  1999. * @page service Service Calls
  2000. * @section bx_base_general Base General
  2001. * @subsection bx_base_general-menu Menu
  2002. * @subsubsection bx_base_general-entity_all_actions entity_all_actions
  2003. *
  2004. * @code bx_srv('bx_posts', 'entity_all_actions', [...]); @endcode
  2005. *
  2006. * Entry actions and social sharing actions
  2007. * @param $mixedContent content ID
  2008. * @param $aParams additional params
  2009. *
  2010. * @see BxBaseModGeneralModule::serviceEntityAllActions
  2011. */
  2012. /**
  2013. * @ref bx_base_general-entity_all_actions "entity_all_actions"
  2014. */
  2015. public function serviceEntityAllActions ($mixedContent = false, $aParams = array())
  2016. {
  2017. $mixedResult = $this->getEntryAllActions($mixedContent, $aParams);
  2018. if(bx_is_api())
  2019. return [bx_api_get_block('entity_actions', $mixedResult)];
  2020. else
  2021. return $this->_oTemplate->entryAllActions($mixedResult);
  2022. }
  2023. /**
  2024. * @page service Service Calls
  2025. * @section bx_base_general Base General
  2026. * @subsection bx_base_general-menu Menu
  2027. * @subsubsection bx_base_general-entity_actions entity_actions
  2028. *
  2029. * @code bx_srv('bx_posts', 'entity_actions', [...]); @endcode
  2030. *
  2031. * Entry actions, without social sharing actions
  2032. * @param $iContentId content ID
  2033. *
  2034. * @see BxBaseModGeneralModule::serviceEntityActions
  2035. */
  2036. /**
  2037. * @ref bx_base_general-entity_actions "entity_actions"
  2038. */
  2039. public function serviceEntityActions ($iContentId = 0)
  2040. {
  2041. $iContentId = $this->_getContent($iContentId, false);
  2042. if($iContentId === false)
  2043. return false;
  2044. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  2045. return $oMenu ? $oMenu->getCode() : false;
  2046. }
  2047. /**
  2048. * @page service Service Calls
  2049. * @section bx_base_general Base General
  2050. * @subsection bx_base_general-page_blocks Page Blocks
  2051. * @subsubsection bx_base_general-entity_reports entity_reports
  2052. *
  2053. * @code bx_srv('bx_posts', 'entity_reports', [...]); @endcode
  2054. *
  2055. * Get content reports
  2056. * @param $iContentId content ID
  2057. *
  2058. * @see BxBaseModGeneralModule::serviceEntityReports
  2059. */
  2060. /**
  2061. * @ref bx_base_general-entity_reports "entity_reports"
  2062. */
  2063. public function serviceEntityReports ($iContentId = 0)
  2064. {
  2065. $mixedContent = $this->_getContent($iContentId);
  2066. list($iContentId, $aContentInfo) = $mixedContent;
  2067. if($iContentId === false)
  2068. return false;
  2069. $CNF = &$this->_oConfig->CNF;
  2070. if (!isset($CNF['OBJECT_REPORTS']) || !isset($CNF['OBJECT_NOTES']))
  2071. return false;
  2072. if(!$aContentInfo || !(BxDolAcl::getInstance()->isMemberLevelInSet(192) || (isset($CNF['FIELD_AUTHOR']) && bx_get_logged_profile_id() == $aContentInfo[$CNF['FIELD_AUTHOR']])))
  2073. return false;
  2074. $oReport = BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $iContentId, true);
  2075. if(!$oReport)
  2076. return false;
  2077. return $oReport->getReportedByWithComments($CNF['OBJECT_NOTES']);
  2078. }
  2079. /**
  2080. * @page service Service Calls
  2081. * @section bx_base_general Base General
  2082. * @subsection bx_base_general-page_blocks Page Blocks
  2083. * @subsubsection bx_base_general-reports_count_by_status reports_count_by_status
  2084. *
  2085. * @code bx_srv('bx_posts', 'reports_count_by_status', [...]); @endcode
  2086. *
  2087. * Get number of reports with specified status
  2088. * @param $iStatus status ID
  2089. *
  2090. * @see BxBaseModGeneralModule::serviceReportsCountByStatus
  2091. */
  2092. /**
  2093. * @ref bx_base_general-entity_reports "entity_reports"
  2094. */
  2095. public function serviceReportsCountByStatus ($iStatus)
  2096. {
  2097. $CNF = &$this->_oConfig->CNF;
  2098. if (!isset($CNF['OBJECT_REPORTS']) || !isset($CNF['OBJECT_NOTES']))
  2099. return false;
  2100. $oReport = BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], 0, false);
  2101. return $oReport->getCountByStatus($iStatus);
  2102. }
  2103. /**
  2104. * @page service Service Calls
  2105. * @section bx_base_general Base General
  2106. * @subsection bx_base_general-menu Menu
  2107. * @subsubsection bx_base_general-entity_social_sharing entity_social_sharing
  2108. *
  2109. * @code bx_srv('bx_posts', 'entity_social_sharing', [...]); @endcode
  2110. *
  2111. * Entry social sharing actions
  2112. * @param $mixedContent content ID or array with integer content ID and
  2113. * array with content info, or false
  2114. * @param $aParams array with additional custom params
  2115. * which may overwrite some default values
  2116. *
  2117. * @see BxBaseModGeneralModule::serviceEntitySocialSharing
  2118. */
  2119. /**
  2120. * @ref bx_base_general-entity_social_sharing "entity_social_sharing"
  2121. */
  2122. public function serviceEntitySocialSharing($mixedContent = false, $aParams = array())
  2123. {
  2124. if(!empty($mixedContent)) {
  2125. if(!is_array($mixedContent))
  2126. $mixedContent = array((int)$mixedContent, array());
  2127. }
  2128. else {
  2129. $mixedContent = $this->_getContent();
  2130. if($mixedContent === false)
  2131. return false;
  2132. }
  2133. list($iContentId, $aContentInfo) = $mixedContent;
  2134. $CNF = &$this->_oConfig->CNF;
  2135. $sUri = !empty($aParams['uri']) ? $aParams['uri'] : '';
  2136. if(empty($sUri) && !empty($CNF['URI_VIEW_ENTRY']))
  2137. $sUri = $CNF['URI_VIEW_ENTRY'];
  2138. $sUrl = !empty($sUri) ? BxDolPermalinks::getInstance()->permalink('page.php?i=' . $sUri . '&id=' . $iContentId) : '';
  2139. $sTitle = !empty($aParams['title']) ? $aParams['title'] : '';
  2140. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  2141. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  2142. $aMarkers = array(
  2143. 'id' => $iContentId,
  2144. 'module' => $this->_aModule['name'],
  2145. 'url' => bx_absolute_url($sUrl),
  2146. 'title' => $sTitle,
  2147. );
  2148. $iIdThumb = !empty($aParams['id_thumb']) ? (int)$aParams['id_thumb'] : 0;
  2149. if(empty($iIdThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  2150. $iIdThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  2151. if ($iIdThumb) {
  2152. $sTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : '';
  2153. $sStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : '';
  2154. if(empty($sStorage) && !empty($CNF['OBJECT_STORAGE']))
  2155. $sStorage = $CNF['OBJECT_STORAGE'];
  2156. if(!empty($sTranscoder))
  2157. $o = BxDolTranscoder::getObjectInstance($sTranscoder);
  2158. else if(!empty($sStorage))
  2159. $o = BxDolStorage::getObjectInstance($sStorage);
  2160. $sImgUrl = $o ? $o->getFileUrlById($iIdThumb) : '';
  2161. if($sImgUrl)
  2162. $aMarkers['img_url'] = $sImgUrl;
  2163. }
  2164. $oMenu = BxDolMenu::getObjectInstance('sys_social_sharing');
  2165. $oMenu->addMarkers($aMarkers);
  2166. $sMenu = $oMenu->getCode();
  2167. if(empty($sMenu))
  2168. return '';
  2169. return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
  2170. 'menu' => $sMenu
  2171. ));
  2172. }
  2173. /**
  2174. * Entry context block
  2175. */
  2176. public function serviceEntityContext ($iContentId = 0)
  2177. {
  2178. return $this->_serviceTemplateFunc ('entryContext', $iContentId);
  2179. }
  2180. /**
  2181. * Blocks for lables tree browsing
  2182. */
  2183. public function serviceGetLablesTree()
  2184. {
  2185. $aBreadcrumbs = array();
  2186. $this->_getLablesBreadcrumbsArray(bx_get('label'), $aBreadcrumbs);
  2187. return $this->_getLablesTreeLevel($aBreadcrumbs);
  2188. }
  2189. public function serviceGetLablesBreadcrumbs()
  2190. {
  2191. if (bx_get('label')){
  2192. $aBreadcrumbs = array();
  2193. $this->_getLablesBreadcrumbsArray(bx_process_input(bx_get('label'), BX_DATA_INT), $aBreadcrumbs);
  2194. $aLabels = array();
  2195. foreach (array_reverse($aBreadcrumbs) as $aLabel){
  2196. $aLabels[] = array(
  2197. 'value' => $aLabel['value'],
  2198. 'url' => $this->_getLablesBrowseUrl($aLabel['id'])
  2199. );
  2200. }
  2201. return $this->_oTemplate->parseHtmlByName('labels_breadcrumbs.html', array('bx_repeat:items' => $aLabels));
  2202. }
  2203. return '';
  2204. }
  2205. public function serviceBrowseByLabel()
  2206. {
  2207. $CNF = &$this->_oConfig->CNF;
  2208. if(empty($CNF['OBJECT_METATAGS']))
  2209. return '';
  2210. $sMode = 'recent';
  2211. if(bx_srv('system', 'is_module_content', [$this->_aModule['name']]))
  2212. $sMode = 'public';
  2213. $o = $this->getObjectBrowse($sMode);
  2214. $o->setDesignBoxTemplateId(BX_DB_PADDING_DEF);
  2215. $o->setDisplayEmptyMsg(true);
  2216. $o->setAjaxPaginate(false);
  2217. $o->setUnitParams(['context' => $sMode]);
  2218. if(($mixedLabel = bx_get('label')) !== false) {
  2219. $sLabel = '';
  2220. if(is_numeric($mixedLabel) && ($aLabel = BxDolLabel::getInstance()->getLabels(['type' => 'id', 'id' => (int)$mixedLabel])) && is_array($aLabel))
  2221. $sLabel = $aLabel['value'];
  2222. else
  2223. $sLabel = bx_process_url_param($mixedLabel, "/^[\d\w\s_-]+$/");
  2224. if($sLabel)
  2225. BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS'])->keywordsSetSearchCondition($o, $sLabel);
  2226. }
  2227. if($o->isError)
  2228. return '';
  2229. if($s = $o->processing())
  2230. return $s;
  2231. else
  2232. return '';
  2233. }
  2234. public function serviceBrowseByCategories($sUnitView, $bEmptyMessage, $bAjaxPaginate, $sMode, $iPerPage)
  2235. {
  2236. $o = $this->getObjectBrowse($sMode, ['unit_view' => $sUnitView]);
  2237. $o->setDesignBoxTemplateId(BX_DB_PADDING_DEF);
  2238. $o->setDisplayEmptyMsg($bEmptyMessage);
  2239. $o->setAjaxPaginate($bAjaxPaginate);
  2240. $o->setCategoryObject('multi');
  2241. $aCategories = BxDolCategories::getInstance()->getData([
  2242. 'type' => 'by_module_with_num',
  2243. 'module' => $this->_aModule['name']
  2244. ]);
  2245. $aCategoriesOutput = [];
  2246. foreach($aCategories as $aCategory) {
  2247. if($aCategory['num'] > 0) {
  2248. $o->setCustomSearchCondition(['keyword' => $aCategory['value']]);
  2249. $o->setPaginatePerPage($iPerPage);
  2250. if(!$o->isError){
  2251. $aResult = $o->processing();
  2252. if($aResult && $aResult['content'] != '')
  2253. $aCategoriesOutput[] = [
  2254. 'name' => _t($aCategory['value']),
  2255. 'url' => '',
  2256. 'content' => $aResult['content']
  2257. ];
  2258. }
  2259. }
  2260. }
  2261. return $this->_oTemplate->parseHtmlByName('browse_by_categories.html', [
  2262. 'bx_repeat:categories' => $aCategoriesOutput,
  2263. ]);
  2264. }
  2265. /**
  2266. * @page service Service Calls
  2267. * @section bx_base_general Base General
  2268. * @subsection bx_base_general-polls Polls Blocks
  2269. * @subsubsection bx_base_general-get_block_poll_answers get_block_poll_answers
  2270. *
  2271. * @code bx_srv('bx_posts', 'get_block_poll_answers', [...]); @endcode
  2272. *
  2273. * Get block with poll answers
  2274. * @param $iPollId poll ID
  2275. *
  2276. * @see BxBaseModGeneralModule::serviceGetBlockPollAnswers
  2277. */
  2278. /**
  2279. * @ref bx_base_general-get_block_poll_answers "get_block_poll_answers"
  2280. */
  2281. public function serviceGetBlockPollAnswers($iPollId, $bForceDisplay = false)
  2282. {
  2283. if(!$iPollId)
  2284. return false;
  2285. if(!$bForceDisplay && $this->isPollPerformed($iPollId))
  2286. return $this->serviceGetBlockPollResults($iPollId);
  2287. return $this->_serviceTemplateFunc('entryPollAnswers', $iPollId, 'getPollInfoById');
  2288. }
  2289. /**
  2290. * @page service Service Calls
  2291. * @section bx_base_general Base General
  2292. * @subsection bx_base_general-polls Polls Blocks
  2293. * @subsubsection bx_base_general-get_block_poll_results get_block_poll_results
  2294. *
  2295. * @code bx_srv('bx_posts', 'get_block_poll_results', [...]); @endcode
  2296. *
  2297. * Get block with poll results
  2298. * @param $iPollId poll ID
  2299. *
  2300. * @see BxBaseModGeneralModule::serviceGetBlockPollResults
  2301. */
  2302. /**
  2303. * @ref bx_base_general-get_block_poll_results "get_block_poll_results"
  2304. */
  2305. public function serviceGetBlockPollResults($iPollId)
  2306. {
  2307. return $this->_serviceTemplateFunc('entryPollResults', $iPollId, 'getPollInfoById');
  2308. }
  2309. /**
  2310. * Data for Notifications module
  2311. */
  2312. public function serviceGetNotificationsData()
  2313. {
  2314. $sModule = $this->_aModule['name'];
  2315. $sEventPrivacy = $sModule . '_allow_view_event_to';
  2316. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  2317. $sEventPrivacy = '';
  2318. $aResult = [
  2319. 'handlers' => [
  2320. ['group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'added', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy],
  2321. ['group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'],
  2322. ['group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted'],
  2323. ['group' => $sModule . '_object_approved', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'approved', 'module_name' => $sModule, 'module_method' => 'get_notifications_post_approved', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy],
  2324. ['group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy],
  2325. ['group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'],
  2326. ['group' => $sModule . '_reply', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'replyPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_reply', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy],
  2327. ['group' => $sModule . '_reply', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'replyRemoved'],
  2328. ['group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy],
  2329. ['group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'],
  2330. ['group' => $sModule . '_reaction', 'type' => 'insert', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_reaction', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy],
  2331. ['group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote'],
  2332. ['group' => $sModule . '_score_up', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteUp', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_up', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy],
  2333. ['group' => $sModule . '_score_down', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteDown', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_down', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy],
  2334. //--- Moderation related: For 'admins'.
  2335. ['group' => $sModule . '_object_pending_approval', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'pending_approval', 'module_name' => $sModule, 'module_method' => 'get_notifications_post_pending_approval', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy],
  2336. ['group' => $sModule . '_object_reported', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'reported_content', 'module_name' => $sModule, 'module_method' => 'get_notifications_post_reported', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy],
  2337. ],
  2338. 'settings' => [
  2339. ['group' => 'content', 'unit' => $sModule, 'action' => 'added', 'types' => ['follow_member', 'follow_context']],
  2340. ['group' => 'content_updated', 'unit' => $sModule, 'action' => 'approved', 'types' => ['personal']],
  2341. ['group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => ['personal', 'follow_member', 'follow_context']],
  2342. ['group' => 'reply', 'unit' => $sModule, 'action' => 'replyPost', 'types' => ['personal']],
  2343. ['group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => ['personal', 'follow_member', 'follow_context']],
  2344. ['group' => 'vote', 'unit' => $sModule . '_reactions', 'action' => 'doVote', 'types' => ['personal', 'follow_member', 'follow_context']],
  2345. ['group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => ['personal', 'follow_member', 'follow_context']],
  2346. ['group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => ['personal', 'follow_member', 'follow_context']],
  2347. //--- Moderation related: For 'admins'.
  2348. ['group' => 'action_required', 'unit' => $sModule, 'action' => 'pending_approval', 'types' => ['personal']],
  2349. ['group' => 'action_required', 'unit' => $sModule, 'action' => 'reported_content', 'types' => ['personal']],
  2350. ],
  2351. 'alerts' => [
  2352. ['unit' => $sModule, 'action' => 'added'],
  2353. ['unit' => $sModule, 'action' => 'edited'],
  2354. ['unit' => $sModule, 'action' => 'deleted'],
  2355. ['unit' => $sModule, 'action' => 'approved'],
  2356. ['unit' => $sModule, 'action' => 'commentPost'],
  2357. ['unit' => $sModule, 'action' => 'commentRemoved'],
  2358. ['unit' => $sModule, 'action' => 'replyPost'],
  2359. ['unit' => $sModule, 'action' => 'replyRemoved'],
  2360. ['unit' => $sModule, 'action' => 'doVote'],
  2361. ['unit' => $sModule, 'action' => 'undoVote'],
  2362. ['unit' => $sModule . '_reactions', 'action' => 'doVote'],
  2363. ['unit' => $sModule . '_reactions', 'action' => 'undoVote'],
  2364. ['unit' => $sModule, 'action' => 'doVoteUp'],
  2365. ['unit' => $sModule, 'action' => 'doVoteDown'],
  2366. //--- Moderation related: For 'admins'.
  2367. ['unit' => $sModule, 'action' => 'pending_approval'],
  2368. ['unit' => $sModule, 'action' => 'reported_content'],
  2369. ]
  2370. ];
  2371. if(!empty($this->_oConfig->CNF['FIELDS_DELAYED_PROCESSING'])) {
  2372. $aResult['handlers'] = array_merge($aResult['handlers'], [
  2373. ['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', 'module_event_privacy' => ''],
  2374. ['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', 'module_event_privacy' => ''],
  2375. ]);
  2376. $aResult['settings'] = array_merge($aResult['settings'], [
  2377. ['group' => 'content_updated', 'unit' => $sModule, 'action' => 'publish_failed', 'types' => ['personal']],
  2378. ['group' => 'content_updated', 'unit' => $sModule, 'action' => 'publish_succeeded', 'types' => ['personal']],
  2379. ]);
  2380. $aResult['alerts'] = array_merge($aResult['alerts'], [
  2381. ['unit' => $sModule, 'action' => 'publish_failed'],
  2382. ['unit' => $sModule, 'action' => 'publish_succeeded'],
  2383. ]);
  2384. }
  2385. return $aResult;
  2386. }
  2387. /**
  2388. * Entry post for Notifications module
  2389. */
  2390. public function serviceGetNotificationsPost($aEvent)
  2391. {
  2392. $CNF = &$this->_oConfig->CNF;
  2393. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  2394. if(empty($aContentInfo) || !is_array($aContentInfo))
  2395. return [];
  2396. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]), '{bx_url_root}');
  2397. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  2398. $sEntrySummary = isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  2399. return [
  2400. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2401. 'entry_url' => $sEntryUrl,
  2402. 'entry_caption' => $sEntryCaption,
  2403. 'entry_summary' => $sEntrySummary,
  2404. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  2405. 'entry_privacy' => '', //may be empty or not specified. In this case Public privacy will be used.
  2406. 'lang_key' => '', //may be empty or not specified, or a string, or an array('site' => '...', 'email' => '...', 'push' => '...'). In this case of empty/not specified the default one from Notification module will be used.
  2407. /*
  2408. * Custom settings for email and/or push notifications can be provided here.
  2409. * Only necessary parts of 'settings' array can be used.
  2410. *
  2411. 'settings' => array(
  2412. 'email' => array(
  2413. 'template' => '', //--- custom email template
  2414. 'markers' => '', //--- markers to parse email parts (subject, body) with
  2415. 'subject' => '' //--- custom email subject
  2416. ),
  2417. 'push' => array(
  2418. 'subject' => '' //--- custom push notification subject
  2419. )
  2420. )
  2421. */
  2422. ];
  2423. }
  2424. public function serviceGetNotificationsPostPendingApproval($aEvent)
  2425. {
  2426. return $this->serviceGetNotificationsPostForModeration($aEvent);
  2427. }
  2428. public function serviceGetNotificationsPostReported($aEvent)
  2429. {
  2430. return $this->serviceGetNotificationsPostForModeration($aEvent);
  2431. }
  2432. public function serviceGetNotificationsPostForModeration($aEvent)
  2433. {
  2434. $aResult = $this->serviceGetNotificationsPost($aEvent);
  2435. /**
  2436. * Unset Entry Author because the notification is addressed to 'admins'.
  2437. */
  2438. if(isset($aResult['entry_author']))
  2439. unset($aResult['entry_author']);
  2440. return $aResult;
  2441. }
  2442. public function serviceGetNotificationsPostApproved($aEvent)
  2443. {
  2444. return $this->serviceGetNotificationsPost($aEvent);
  2445. }
  2446. public function serviceGetNotificationsPostPublishFailed($aEvent)
  2447. {
  2448. return $this->serviceGetNotificationsPost($aEvent);
  2449. }
  2450. public function serviceGetNotificationsPostPublishSucceeded($aEvent)
  2451. {
  2452. return $this->serviceGetNotificationsPost($aEvent);
  2453. }
  2454. /**
  2455. * Entry post comment for Notifications module
  2456. */
  2457. public function serviceGetNotificationsComment($aEvent)
  2458. {
  2459. $CNF = &$this->_oConfig->CNF;
  2460. $iContentId = (int)$aEvent['object_id'];
  2461. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2462. if(empty($aContentInfo) || !is_array($aContentInfo))
  2463. return [];
  2464. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  2465. if(!$oComment || !$oComment->isEnabled())
  2466. return [];
  2467. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]), '{bx_url_root}');
  2468. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  2469. $sEntrySummary = isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  2470. $iCommentId = (int)$aEvent['subobject_id'];
  2471. return [
  2472. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2473. 'entry_url' => $sEntryUrl,
  2474. 'entry_caption' => $sEntryCaption,
  2475. 'entry_summary' => $sEntrySummary,
  2476. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  2477. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  2478. 'subentry_url' => $oComment->getItemUrl($iCommentId, '{bx_url_root}'),
  2479. 'subentry_url_api' => $oComment->getItemUrlApi($iCommentId, '{bx_url_root}'),
  2480. 'subentry_summary' => $oComment->getViewText($iCommentId),
  2481. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2482. ];
  2483. }
  2484. /**
  2485. * Entry post reply for Notifications module
  2486. */
  2487. public function serviceGetNotificationsReply($aEvent)
  2488. {
  2489. $CNF = &$this->_oConfig->CNF;
  2490. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], 0, false);
  2491. if(!$oComment || !$oComment->isEnabled())
  2492. return [];
  2493. $iParentId = (int)$aEvent['object_id'];
  2494. $aParentInfo = $oComment->getQueryObject()->getCommentsBy(['type' => 'id', 'id' => $iParentId]);
  2495. if(empty($aParentInfo) || !is_array($aParentInfo))
  2496. return [];
  2497. $iObjectId = (int)$aParentInfo['cmt_object_id'];
  2498. $oComment->init($iObjectId);
  2499. $iCommentId = (int)$aEvent['subobject_id'];
  2500. return [
  2501. 'object_id' => $iObjectId,
  2502. 'entry_sample' => '_cmt_txt_sample_comment_single',
  2503. 'entry_url' => $oComment->getItemUrl($iParentId, '{bx_url_root}'),
  2504. 'entry_url_api' => $oComment->getItemUrlApi($iParentId, '{bx_url_root}'),
  2505. 'entry_caption' => strmaxtextlen($aParentInfo['cmt_text'], 20, '...'),
  2506. 'entry_summary' => $oComment->getViewText($iParentId),
  2507. 'entry_author' => (int)$aParentInfo['cmt_author_id'],
  2508. 'subentry_sample' => '_cmt_txt_sample_reply_to',
  2509. 'subentry_url' => $oComment->getItemUrl($iCommentId, '{bx_url_root}'),
  2510. 'subentry_url_api' => $oComment->getItemUrlApi($iCommentId, '{bx_url_root}'),
  2511. 'subentry_summary' => $oComment->getViewText($iCommentId),
  2512. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2513. ];
  2514. }
  2515. /**
  2516. * Entry post vote for Notifications module
  2517. */
  2518. public function serviceGetNotificationsVote($aEvent)
  2519. {
  2520. $CNF = &$this->_oConfig->CNF;
  2521. $iContentId = (int)$aEvent['object_id'];
  2522. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2523. if(empty($aContentInfo) || !is_array($aContentInfo))
  2524. return [];
  2525. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  2526. if(!$oVote || !$oVote->isEnabled())
  2527. return [];
  2528. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]), '{bx_url_root}');
  2529. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  2530. $sEntrySummary = isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  2531. return [
  2532. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2533. 'entry_url' => $sEntryUrl,
  2534. 'entry_caption' => $sEntryCaption,
  2535. 'entry_summary' => $sEntrySummary,
  2536. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  2537. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  2538. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2539. ];
  2540. }
  2541. /**
  2542. * Entry post vote for Notifications module
  2543. */
  2544. public function serviceGetNotificationsReaction($aEvent)
  2545. {
  2546. $CNF = &$this->_oConfig->CNF;
  2547. $iContentId = (int)$aEvent['object_id'];
  2548. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2549. if(empty($aContentInfo) || !is_array($aContentInfo))
  2550. return [];
  2551. $oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $iContentId);
  2552. if(!$oReaction || !$oReaction->isEnabled())
  2553. return [];
  2554. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  2555. if(empty($aSubentry) || !is_array($aSubentry))
  2556. return [];
  2557. $aSubentrySampleParams = array();
  2558. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  2559. if(!empty($aReaction['title']))
  2560. $aSubentrySampleParams[] = $aReaction['title'];
  2561. else
  2562. $aSubentrySampleParams[] = '_undefined';
  2563. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]), '{bx_url_root}');
  2564. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  2565. $sEntrySummary = isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  2566. return [
  2567. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2568. 'entry_url' => $sEntryUrl,
  2569. 'entry_caption' => $sEntryCaption,
  2570. 'entry_summary' => $sEntrySummary,
  2571. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  2572. 'subentry_sample' => $CNF['T']['txt_sample_reaction_single'],
  2573. 'subentry_sample_params' => $aSubentrySampleParams,
  2574. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2575. ];
  2576. }
  2577. /**
  2578. * Entry post score -> vote up for Notifications module
  2579. */
  2580. public function serviceGetNotificationsScoreUp($aEvent)
  2581. {
  2582. return $this->_serviceGetNotificationsScore('up', $aEvent);
  2583. }
  2584. /**
  2585. * Entry post score -> vote up for Notifications module
  2586. */
  2587. public function serviceGetNotificationsScoreDown($aEvent)
  2588. {
  2589. return $this->_serviceGetNotificationsScore('down', $aEvent);
  2590. }
  2591. protected function _serviceGetNotificationsScore($sType, $aEvent)
  2592. {
  2593. $CNF = &$this->_oConfig->CNF;
  2594. $iContentId = (int)$aEvent['object_id'];
  2595. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2596. if(empty($aContentInfo) || !is_array($aContentInfo))
  2597. return array();
  2598. $oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContentId);
  2599. if(!$oScore || !$oScore->isEnabled())
  2600. return array();
  2601. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]), '{bx_url_root}');
  2602. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  2603. $sEntrySummary = isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  2604. return [
  2605. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2606. 'entry_url' => $sEntryUrl,
  2607. 'entry_caption' => $sEntryCaption,
  2608. 'entry_summary' => $sEntrySummary,
  2609. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  2610. 'subentry_sample' => $CNF['T']['txt_sample_score_' . $sType . '_single'],
  2611. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2612. ];
  2613. }
  2614. /**
  2615. * Data for Reputation module
  2616. */
  2617. public function serviceGetReputationData()
  2618. {
  2619. $sModule = $this->_aModule['name'];
  2620. $aResult = [
  2621. 'handlers' => [
  2622. ['group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'added', 'points_active' => 3, 'points_passive' => 0],
  2623. ['group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted', 'points_active' => -3, 'points_passive' => 0],
  2624. ['group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'points_active' => 2, 'points_passive' => 1],
  2625. ['group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved', 'points_active' => -2, 'points_passive' => -1],
  2626. ['group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'points_active' => 1, 'points_passive' => 1],
  2627. ['group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote', 'points_active' => -1, 'points_passive' => -1],
  2628. ['group' => $sModule . '_reaction', 'type' => 'insert', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'doVote', 'points_active' => 1, 'points_passive' => 1],
  2629. ['group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote', 'points_active' => -1, 'points_passive' => -1],
  2630. ['group' => $sModule . '_score_up', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteUp', 'points_active' => 1, 'points_passive' => 1],
  2631. ['group' => $sModule . '_score_up', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVoteUp', 'points_active' => -1, 'points_passive' => -1],
  2632. ['group' => $sModule . '_score_down', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteDown', 'points_active' => 1, 'points_passive' => -1],
  2633. ['group' => $sModule . '_score_down', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVoteDown', 'points_active' => -1, 'points_passive' => 1],
  2634. ],
  2635. 'alerts' => [
  2636. ['unit' => $sModule, 'action' => 'added'],
  2637. ['unit' => $sModule, 'action' => 'deleted'],
  2638. ['unit' => $sModule, 'action' => 'commentPost'],
  2639. ['unit' => $sModule, 'action' => 'commentRemoved'],
  2640. ['unit' => $sModule, 'action' => 'doVote'],
  2641. ['unit' => $sModule, 'action' => 'undoVote'],
  2642. ['unit' => $sModule . '_reactions', 'action' => 'doVote'],
  2643. ['unit' => $sModule . '_reactions', 'action' => 'undoVote'],
  2644. ['unit' => $sModule, 'action' => 'doVoteUp'],
  2645. ['unit' => $sModule, 'action' => 'undoVoteUp'],
  2646. ['unit' => $sModule, 'action' => 'doVoteDown'],
  2647. ['unit' => $sModule, 'action' => 'undoVoteDown'],
  2648. ]
  2649. ];
  2650. return $aResult;
  2651. }
  2652. /**
  2653. * Data for Timeline module
  2654. */
  2655. public function serviceGetTimelineData()
  2656. {
  2657. $sModule = $this->_aModule['name'];
  2658. return array(
  2659. 'handlers' => array(
  2660. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'added', 'module_name' => $sModule, 'module_method' => 'get_timeline_post', 'module_class' => 'Module', 'groupable' => 0, 'group_by' => ''),
  2661. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  2662. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted')
  2663. ),
  2664. 'alerts' => array(
  2665. array('unit' => $sModule, 'action' => 'added'),
  2666. array('unit' => $sModule, 'action' => 'edited'),
  2667. array('unit' => $sModule, 'action' => 'deleted'),
  2668. )
  2669. );
  2670. }
  2671. /**
  2672. * Entry post for Timeline module
  2673. */
  2674. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  2675. {
  2676. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  2677. if(empty($aContentInfo) || !is_array($aContentInfo))
  2678. return false;
  2679. $CNF = &$this->_oConfig->CNF;
  2680. if((!empty($CNF['FIELD_STATUS']) && $aContentInfo[$CNF['FIELD_STATUS']] != 'active') || (!empty($CNF['FIELD_STATUS_ADMIN']) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != 'active'))
  2681. return false;
  2682. $bCache = true;
  2683. $iUserId = $this->getUserId();
  2684. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  2685. $iAuthorIdAbs = abs($iAuthorId);
  2686. /**
  2687. * Don't show anonymous posts on the post's owner timeline
  2688. * and don't cache them when they're viewed by their authors.
  2689. */
  2690. if($iAuthorId < 0 && ((is_numeric($aEvent['owner_id']) && $iAuthorIdAbs == (int)$aEvent['owner_id']) || (is_array($aEvent['owner_id']) && in_array($iAuthorIdAbs, $aEvent['owner_id'])))) {
  2691. if($iAuthorIdAbs != $iUserId)
  2692. return false;
  2693. $bCache = false;
  2694. }
  2695. //--- Views
  2696. $oViews = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  2697. $aViews = array();
  2698. if ($oViews && $oViews->isEnabled())
  2699. $aViews = array(
  2700. 'system' => $CNF['OBJECT_VIEWS'],
  2701. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  2702. 'count' => $aContentInfo['views']
  2703. );
  2704. //--- Votes
  2705. $oVotes = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  2706. $aVotes = array();
  2707. if ($oVotes && $oVotes->isEnabled())
  2708. $aVotes = array(
  2709. 'system' => $CNF['OBJECT_VOTES'],
  2710. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  2711. 'count' => $aContentInfo['votes']
  2712. );
  2713. //--- Reactions
  2714. $oReactions = isset($CNF['OBJECT_REACTIONS']) ? BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  2715. $aReactions = array();
  2716. if ($oReactions && $oReactions->isEnabled())
  2717. $aReactions = array(
  2718. 'system' => $CNF['OBJECT_REACTIONS'],
  2719. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  2720. 'count' => $aContentInfo['rvotes']
  2721. );
  2722. //--- Scores
  2723. $oScores = isset($CNF['OBJECT_SCORES']) ? BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  2724. $aScores = array();
  2725. if ($oScores && $oScores->isEnabled())
  2726. $aScores = array(
  2727. 'system' => $CNF['OBJECT_SCORES'],
  2728. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  2729. 'score' => $aContentInfo['score']
  2730. );
  2731. //--- Reports
  2732. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  2733. $aReports = array();
  2734. if ($oReports && $oReports->isEnabled())
  2735. $aReports = array(
  2736. 'system' => $CNF['OBJECT_REPORTS'],
  2737. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  2738. 'count' => $aContentInfo['reports']
  2739. );
  2740. //--- Comments
  2741. $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  2742. $aComments = array();
  2743. if($oCmts && $oCmts->isEnabled())
  2744. $aComments = array(
  2745. 'system' => $CNF['OBJECT_COMMENTS'],
  2746. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  2747. 'count' => $aContentInfo['comments']
  2748. );
  2749. //--- Title & Description
  2750. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  2751. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  2752. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  2753. $iOwnerId = $iAuthorIdAbs;
  2754. if(isset($aEvent['object_privacy_view']) && (int)$aEvent['object_privacy_view'] < 0)
  2755. $iOwnerId = abs($aEvent['object_privacy_view']);
  2756. $aContent = $this->_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  2757. if(isset($aContent['_cache'])) {
  2758. if($bCache)
  2759. $bCache = (bool)$aContent['_cache'];
  2760. unset($aContent['_cache']);
  2761. }
  2762. return [
  2763. '_cache' => $bCache,
  2764. 'owner_id' => $iOwnerId,
  2765. 'object_owner_id' => $iAuthorId,
  2766. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  2767. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  2768. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  2769. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  2770. 'url' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']])),
  2771. 'content' => $aContent, //a string to display or array to parse default template before displaying.
  2772. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  2773. 'views' => $aViews,
  2774. 'votes' => $aVotes,
  2775. 'reactions' => $aReactions,
  2776. 'scores' => $aScores,
  2777. 'reports' => $aReports,
  2778. 'comments' => $aComments,
  2779. 'title' => $sTitle, //may be empty.
  2780. 'description' => '' //may be empty.
  2781. ];
  2782. }
  2783. public function serviceGetTimelinePostAllowedView($aEvent)
  2784. {
  2785. $iContentId = (int)$aEvent['object_id'];
  2786. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2787. if(empty($aContentInfo) || !is_array($aContentInfo))
  2788. return _t('_sys_txt_access_denied');
  2789. return $this->serviceCheckAllowedViewForProfile($aContentInfo);
  2790. }
  2791. /**
  2792. * Check particular action permission without content
  2793. * @param $sAction action to check, for example: Browse, Add
  2794. * @param $iContentId content ID
  2795. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  2796. */
  2797. public function serviceCheckAllowed($sAction, $isPerformAction = false)
  2798. {
  2799. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  2800. if (!method_exists($this, $sMethod))
  2801. return _t('_sys_request_method_not_found_cpt');
  2802. return $this->$sMethod($isPerformAction);
  2803. }
  2804. /**
  2805. * Check particular action permission with content
  2806. * @param $sAction action to check, for example: View, Edit
  2807. * @param $iContentId content ID
  2808. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  2809. */
  2810. public function serviceCheckAllowedWithContent($sAction, $iContentId, $isPerformAction = false)
  2811. {
  2812. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  2813. return _t('_sys_request_page_not_found_cpt');
  2814. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  2815. if (!method_exists($this, $sMethod))
  2816. return _t('_sys_request_method_not_found_cpt');
  2817. return $this->$sMethod($aContentInfo, $isPerformAction);
  2818. }
  2819. /**
  2820. * Check particular action permission with content for specified profile
  2821. * @param $sAction action to check, for example: View, Edit
  2822. * @param $iContentId content ID
  2823. * @param $iProfileId profile ID which the permissions to be cheked for
  2824. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  2825. */
  2826. public function serviceCheckAllowedWithContentForProfile($sAction, $iContentId, $iProfileId, $isPerformAction = false)
  2827. {
  2828. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  2829. return _t('_sys_request_page_not_found_cpt');
  2830. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction) . 'ForProfile';
  2831. if (!method_exists($this, $sMethod))
  2832. return _t('_sys_request_method_not_found_cpt');
  2833. return $this->$sMethod($aContentInfo, $iProfileId, $isPerformAction);
  2834. }
  2835. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  2836. {
  2837. //negative id used in comments for reports
  2838. if ($iContentId < 0)
  2839. return CHECK_ACTION_RESULT_ALLOWED;
  2840. return $this->serviceCheckAllowedWithContent('comments_view', $iContentId);
  2841. }
  2842. public function serviceCheckAllowedCommentsPost($iContentId, $sObjectComments)
  2843. {
  2844. //negative id used in comments for reports
  2845. if ($iContentId < 0)
  2846. return CHECK_ACTION_RESULT_ALLOWED;
  2847. return $this->serviceCheckAllowedWithContent('comments_post', $iContentId);
  2848. }
  2849. public function serviceGetContentOwnerProfileId ($iContentId)
  2850. {
  2851. $CNF = &$this->_oConfig->CNF;
  2852. // file owner must be author of the content or profile itself in case of profile based module
  2853. if ($iContentId) {
  2854. $sModule = $this->getName();
  2855. if ($this instanceof iBxDolProfileService && BxDolService::call($sModule, 'act_as_profile')) {
  2856. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule);
  2857. }
  2858. else {
  2859. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2860. $iContentAuthor = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  2861. if($iContentAuthor < 0)
  2862. $iContentAuthor = abs($iContentAuthor);
  2863. $oProfile = $aContentInfo ? BxDolProfile::getInstance($iContentAuthor) : null;
  2864. }
  2865. $iProfileId = $oProfile ? $oProfile->id() : bx_get_logged_profile_id();
  2866. }
  2867. else
  2868. $iProfileId = bx_get_logged_profile_id();
  2869. return $iProfileId;
  2870. }
  2871. public function serviceGetBadges($iContentId, $bIsSingle = false, $bIsCompact = false)
  2872. {
  2873. $sModule = $this->getName();
  2874. $oBadges = BxDolBadges::getInstance();
  2875. $aBadges = $oBadges->getData(array(
  2876. 'type' => ($bIsSingle ? 'by_module&object2_single' : 'by_module&object2'),
  2877. 'module' => $sModule,
  2878. 'object_id' => $iContentId
  2879. ));
  2880. $sResult = false;
  2881. /**
  2882. * @hooks
  2883. * @hookdef hook-system-get_badges 'system', 'get_badges' - hook to override bages assigned to an entry (content)
  2884. * - $unit_name - equals `system`
  2885. * - $action - equals `get_badges`
  2886. * - $object_id - not used
  2887. * - $sender_id - not used
  2888. * - $extra_params - array of additional params with the following array keys:
  2889. * - `module` - [string] module name
  2890. * - `content_id` - [int] content id
  2891. * - `is_single` - [boolean] only one badge can be used or not
  2892. * - `is_compact` - [boolean] badge in compact mode or not
  2893. * - `badges` - [array] a list of all badges assigned to the content
  2894. * - `override_result` - [string] or [boolean] by ref, if string is returned then it will be used as resulting badges code, can be overridden in hook processing
  2895. * @hook @ref hook-system-get_badges
  2896. */
  2897. bx_alert('system', 'get_badges', 0, 0, [
  2898. 'module' => $sModule,
  2899. 'content_id' => $iContentId,
  2900. 'is_single' => $bIsSingle,
  2901. 'is_compact' => $bIsCompact,
  2902. 'badges' => $aBadges,
  2903. 'override_result' => &$sResult
  2904. ]);
  2905. if($sResult !== false)
  2906. return $sResult;
  2907. if(empty($aBadges) || !is_array($aBadges))
  2908. return $this->_bIsApi ? [] : '';
  2909. if($this->_bIsApi) {
  2910. foreach($aBadges as &$aBadge)
  2911. if(($mixedIcon = $aBadge['icon']) && is_numeric($mixedIcon) && (int)$mixedIcon > 0)
  2912. $aBadge['icon_url'] = $this->_oTemplate->getIcon($aBadge['icon'], ['wrap_in_tag' => false]);
  2913. else
  2914. $aBadge['icon'] = $mixedIcon;
  2915. return $aBadges;
  2916. }
  2917. if($bIsSingle)
  2918. return BxDolService::call('system', 'get_badge', array($aBadges[0], $bIsCompact), 'TemplServices');
  2919. $aBadgesOutput = array();
  2920. foreach($aBadges as $aBadge)
  2921. $aBadgesOutput[] = array('badge' => BxDolService::call('system', 'get_badge', array($aBadge, $bIsCompact), 'TemplServices'));
  2922. return $this->_oTemplate->parseHtmlByName('badges.html', array(
  2923. 'bx_repeat:items' => $aBadgesOutput,
  2924. ));
  2925. }
  2926. /**
  2927. * @page service Service Calls
  2928. * @section bx_base_general Base General
  2929. * @subsection bx_base_general-page_blocks Page Blocks
  2930. * @subsubsection bx_base_general-categories_multi_list categories_multi_list
  2931. *
  2932. * @code bx_srv('bx_posts', 'categories_multi_list', [...]); @endcode
  2933. *
  2934. * Display multi-categorories block with number of posts in each category
  2935. * @param $bAsArray boolean reature as array or not.
  2936. *
  2937. * @see BxBaseModGeneralModule::serviceCategoriesMultiList
  2938. */
  2939. /**
  2940. * @ref bx_base_general-categories_multi_list "categories_multi_list"
  2941. */
  2942. public function serviceCategoriesMultiList($bAsArray = false)
  2943. {
  2944. $oCategories = BxDolCategories::getInstance();
  2945. $oCategories->setModule($this->getName());
  2946. $mixedResult = $oCategories->getCategoriesList($bAsArray || $this->_bIsApi);
  2947. return !$this->_bIsApi ? $mixedResult : [bx_api_get_block('categories_list', $mixedResult)];
  2948. }
  2949. /**
  2950. * ======
  2951. * PERMISSION METHODS
  2952. * ======
  2953. */
  2954. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  2955. {
  2956. $mixedResult = $this->_serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  2957. /**
  2958. * @hooks
  2959. * @hookdef hook-system-check_allowed_view 'system', 'check_allowed_view' - hook to override the result of checking whether 'view' action is allowed or not to specified profile
  2960. * - $unit_name - equals `system`
  2961. * - $action - equals `check_allowed_view`
  2962. * - $object_id - not used
  2963. * - $sender_id - not used
  2964. * - $extra_params - array of additional params with the following array keys:
  2965. * - `module` - [string] module name
  2966. * - `content_info` - [array] content info array as key&value pairs
  2967. * - `profile_id` - [boolean] or [int] profile id to be checked the availability of the action to
  2968. * - `override_result` - [string] or [int] by ref, check action result, can be overridden in hook processing. Return string with an error if action isn't allowed or CHECK_ACTION_RESULT_ALLOWED, @see BxDolAcl
  2969. * @hook @ref hook-system-check_allowed_view
  2970. */
  2971. bx_alert('system', 'check_allowed_view', 0, 0, [
  2972. 'module' => $this->getName(),
  2973. 'content_info' => $aDataEntry,
  2974. 'profile_id' => $iProfileId,
  2975. 'override_result' => &$mixedResult
  2976. ]);
  2977. return $mixedResult;
  2978. }
  2979. public function checkAllowedSetThumb ($iContentId = 0)
  2980. {
  2981. return CHECK_ACTION_RESULT_ALLOWED;
  2982. }
  2983. /**
  2984. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  2985. */
  2986. public function checkAllowedBrowse ()
  2987. {
  2988. $mixedResult = null;
  2989. /**
  2990. * @hooks
  2991. * @hookdef hook-system-check_allowed_browse 'system', 'check_allowed_browse' - hook to override the result of checking whether 'browse' action is allowed or not to currently logged in profile
  2992. * It's equivalent to @ref hook-system-check_allowed_view
  2993. * except `content_info` parameter in $extra_params is missing
  2994. * @hook @ref hook-system-check_allowed_browse
  2995. */
  2996. bx_alert('system', 'check_allowed_browse', 0, 0, [
  2997. 'module' => $this->getName(),
  2998. 'profile_id' => $this->_iProfileId,
  2999. 'override_result' => &$mixedResult
  3000. ]);
  3001. if($mixedResult !== null)
  3002. return $mixedResult;
  3003. return CHECK_ACTION_RESULT_ALLOWED;
  3004. }
  3005. /**
  3006. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  3007. */
  3008. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  3009. {
  3010. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  3011. }
  3012. /**
  3013. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  3014. */
  3015. public function checkAllowedViewForProfile ($aDataEntry, $iProfileId, $isPerformAction = false)
  3016. {
  3017. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  3018. }
  3019. /**
  3020. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  3021. */
  3022. public function checkAllowedAdd ($isPerformAction = false)
  3023. {
  3024. // check ACL
  3025. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  3026. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  3027. return $aCheck[CHECK_ACTION_MESSAGE];
  3028. return CHECK_ACTION_RESULT_ALLOWED;
  3029. }
  3030. public function serviceCheckAllowedAddInContext($sContextModule)
  3031. {
  3032. $CNF = &$this->_oConfig->CNF;
  3033. if(($sKey = 'OBJECT_PRIVACY_VIEW') && !empty($CNF[$sKey]) && ($oPrivacy = BxDolPrivacy::getObjectInstance($CNF[$sKey])) !== false && !$oPrivacy->isAllowedAddInContext($sContextModule))
  3034. return _t('_sys_txt_access_denied');
  3035. return CHECK_ACTION_RESULT_ALLOWED;
  3036. }
  3037. /**
  3038. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  3039. */
  3040. public function checkAllowedApprove ($aDataEntry, $isPerformAction = false)
  3041. {
  3042. $CNF = &$this->_oConfig->CNF;
  3043. $sError = '_sys_txt_access_denied';
  3044. if($this->_oConfig->isAutoApproveEnabled())
  3045. return _t($sError);
  3046. if($aDataEntry[$CNF['FIELD_STATUS_ADMIN']] != BX_BASE_MOD_GENERAL_STATUS_PENDING)
  3047. return _t($sError);
  3048. // moderator always have access
  3049. if ($this->_isModerator($isPerformAction))
  3050. return CHECK_ACTION_RESULT_ALLOWED;
  3051. // check for context's admins
  3052. if (!empty($CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  3053. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$CNF['FIELD_ALLOW_VIEW_TO']]);
  3054. if ($oProfile){
  3055. $sModule = $oProfile->getModule();
  3056. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  3057. $oModule = BxDolModule::getInstance($sModule);
  3058. // check for context's extra roles with rights
  3059. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  3060. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'edit_any');
  3061. if ($bResult !== NULL) return $bResult;
  3062. }
  3063. // if allowed edit a group then allowed to edit anything inside its context
  3064. if(isset($aEntity) && $oModule->checkAllowedEdit($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  3065. return CHECK_ACTION_RESULT_ALLOWED;
  3066. }
  3067. }
  3068. }
  3069. return _t($sError);
  3070. }
  3071. /**
  3072. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  3073. */
  3074. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  3075. {
  3076. // moderator and owner always have access
  3077. if ($this->isEntryAuthor($aDataEntry, $this->_iProfileId) || $this->_isModerator($isPerformAction))
  3078. return CHECK_ACTION_RESULT_ALLOWED;
  3079. // check for context's admins
  3080. if (!empty($this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  3081. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]);
  3082. if ($oProfile){
  3083. $sModule = $oProfile->getModule();
  3084. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  3085. $oModule = BxDolModule::getInstance($sModule);
  3086. // check for context's extra roles with rights
  3087. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  3088. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'edit_any');
  3089. if ($bResult !== NULL) return $bResult;
  3090. }
  3091. // if allowed edit a group then allowed to edit anything inside its context
  3092. if(isset($aEntity) && $oModule->checkAllowedEdit($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  3093. return CHECK_ACTION_RESULT_ALLOWED;
  3094. }
  3095. }
  3096. }
  3097. return _t('_sys_txt_access_denied');
  3098. }
  3099. /**
  3100. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  3101. */
  3102. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  3103. {
  3104. // moderator always has access
  3105. if ($this->_isAdministrator($isPerformAction))
  3106. return CHECK_ACTION_RESULT_ALLOWED;
  3107. // check ACL
  3108. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  3109. if ($this->isEntryAuthor($aDataEntry, $this->_iProfileId) && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  3110. return CHECK_ACTION_RESULT_ALLOWED;
  3111. // check for context's admins
  3112. if (isset($this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0){
  3113. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]);
  3114. if ($oProfile){
  3115. $sModule = $oProfile->getModule();
  3116. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  3117. $oModule = BxDolModule::getInstance($sModule);
  3118. // check for context's extra roles with rights
  3119. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  3120. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'delete_any');
  3121. if ($bResult !== NULL) return $bResult;
  3122. }
  3123. // if allowed delete a group then allowed to delete anything inside its context
  3124. if(isset($aEntity) && $oModule->checkAllowedDelete($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  3125. return CHECK_ACTION_RESULT_ALLOWED;
  3126. }
  3127. }
  3128. }
  3129. return _t('_sys_txt_access_denied');
  3130. }
  3131. /**
  3132. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  3133. */
  3134. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  3135. {
  3136. // admin always has access
  3137. if (isAdmin())
  3138. return CHECK_ACTION_RESULT_ALLOWED;
  3139. // check ACL
  3140. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  3141. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  3142. return $aCheck[CHECK_ACTION_MESSAGE];
  3143. return CHECK_ACTION_RESULT_ALLOWED;
  3144. }
  3145. /**
  3146. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  3147. */
  3148. public function checkAllowedEditAnyEntry ($isPerformAction = false)
  3149. {
  3150. return $this->checkAllowedEditAnyEntryForProfile($isPerformAction, $this->_iProfileId);
  3151. }
  3152. /**
  3153. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  3154. */
  3155. public function checkAllowedDeleteAnyEntry ($isPerformAction = false)
  3156. {
  3157. return $this->checkAllowedDeleteAnyEntryForProfile($isPerformAction, $this->_iProfileId);
  3158. }
  3159. /**
  3160. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  3161. */
  3162. public function checkAllowedEditAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  3163. {
  3164. if(!$iProfileId)
  3165. $iProfileId = $this->_iProfileId;
  3166. $aCheck = checkActionModule($iProfileId, MEMBERSHIP_ACTION_EDIT_ANY_ENTRY, $this->getName(), $isPerformAction);
  3167. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  3168. return CHECK_ACTION_RESULT_ALLOWED;
  3169. return _t('_sys_txt_access_denied');
  3170. }
  3171. /**
  3172. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  3173. */
  3174. public function checkAllowedDeleteAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  3175. {
  3176. if(!$iProfileId)
  3177. $iProfileId = $this->_iProfileId;
  3178. $aCheck = checkActionModule($iProfileId, MEMBERSHIP_ACTION_DELETE_ANY_ENTRY, $this->getName(), $isPerformAction);
  3179. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  3180. return CHECK_ACTION_RESULT_ALLOWED;
  3181. return _t('_sys_txt_access_denied');
  3182. }
  3183. /**
  3184. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  3185. */
  3186. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  3187. {
  3188. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  3189. }
  3190. /**
  3191. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  3192. */
  3193. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  3194. {
  3195. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  3196. }
  3197. protected function _serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId)
  3198. {
  3199. $CNF = &$this->_oConfig->CNF;
  3200. if(!$iProfileId)
  3201. $iProfileId = $this->_iProfileId;
  3202. if(empty($aDataEntry) || !is_array($aDataEntry))
  3203. return _t('_sys_txt_not_found');
  3204. if(!empty($iProfileId) && abs($aDataEntry[$CNF['FIELD_AUTHOR']]) == (int)$iProfileId)
  3205. return CHECK_ACTION_RESULT_ALLOWED;
  3206. // below goes mem cached response for current page load
  3207. $sCacheKey = $this->getName() . ':' . __CLASS__ . ':_checkAllowedViewForProfile:' . $aDataEntry[$CNF['FIELD_ID']] . ':' . $iProfileId;
  3208. $mixedRet = bx_mem_cache_get($sCacheKey);
  3209. if (null !== $mixedRet)
  3210. return $mixedRet;
  3211. $mixedRet = CHECK_ACTION_RESULT_ALLOWED;
  3212. if (empty($iProfileId) || !$this->_isModeratorForProfile($isPerformAction, $iProfileId)) { // skip checking if moderator
  3213. $aCheck = checkActionModule($iProfileId, 'view entry', $this->getName(), $isPerformAction);
  3214. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED) { // check ACL
  3215. $mixedRet = $aCheck[CHECK_ACTION_MESSAGE];
  3216. } elseif(!empty($CNF['OBJECT_PRIVACY_VIEW'])) { // check privacy
  3217. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  3218. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  3219. $mixedRet = _t('_sys_access_denied_to_private_content');
  3220. }
  3221. }
  3222. bx_mem_cache_set($sCacheKey, $mixedRet);
  3223. return $mixedRet;
  3224. }
  3225. public function getObjectBrowse ($sMode, $aParams = false, $sClass = 'SearchResult')
  3226. {
  3227. $oObject = null;
  3228. bx_alert('system', 'get_object_browse', 0, 0, [
  3229. 'module' => $this->getName(),
  3230. 'mode' => &$sMode,
  3231. 'params' => &$aParams,
  3232. 'class' => &$sClass,
  3233. 'object' => &$oObject,
  3234. 'mode_ref' => &$sMode,
  3235. 'params_ref' => &$aParams,
  3236. 'class_ref' => &$sClass,
  3237. 'object_ref' => &$oObject
  3238. ]);
  3239. if($oObject !== null)
  3240. return $oObject;
  3241. if($aParams === false || !is_array($aParams))
  3242. $aParams = [];
  3243. $aParams['class_search_result'] ??= $sClass;
  3244. bx_import($sClass, $this->_aModule);
  3245. $sClass = $this->_aModule['class_prefix'] . $sClass;
  3246. return new $sClass($sMode, $aParams);
  3247. }
  3248. public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
  3249. {
  3250. if(CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  3251. return $this->_bIsApi ? [bx_api_get_msg($sMsg)] : MsgBox($sMsg);
  3252. $o = $this->getObjectBrowse($sMode, $aParams, $sClassSearchResult);
  3253. $o->setDesignBoxTemplateId($iDesignBox);
  3254. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  3255. $o->setAjaxPaginate($bAjaxPaginate);
  3256. $o->setUnitParams(array('context' => $sMode));
  3257. if(isset($aParams['condition']) && is_array($aParams['condition']))
  3258. $o->setCustomCurrentCondition($aParams['condition']);
  3259. if($o->isError)
  3260. return '';
  3261. if($this->_bIsApi) {
  3262. $aBlock = BxDolPage::getBlockProcessing();
  3263. $sContentType = 'browse';
  3264. if(($aConfigApi = $aBlock['config_api'] ?? false) && is_array($aConfigApi))
  3265. $sContentType = $aConfigApi['content_type'] ?? $sContentType;
  3266. $bBrowseSimple = $sContentType == 'browse_simple';
  3267. $a = $o->processingAPI($bBrowseSimple);
  3268. if($a && is_array($a))
  3269. $a['hide_empty_msg'] = !(bool)$bDisplayEmptyMsg;
  3270. return !$bBrowseSimple || $a['data'] ? [bx_api_get_block($sContentType, $a)] : [];
  3271. }
  3272. else
  3273. return ($s = $o->processing()) ? $s : '';
  3274. }
  3275. /**
  3276. * Shows a list of profiles.
  3277. */
  3278. protected function _serviceBrowseQuick($aProfiles, $iStart = 0, $iLimit = 4, $aAdditionalParams = [])
  3279. {
  3280. return bx_srv('system', 'browse_quick', [$aProfiles, $iStart, $iLimit, ['additional_params' => $aAdditionalParams]], 'TemplServiceProfiles');
  3281. }
  3282. // ====== COMMON METHODS
  3283. public function isPollPerformed($iObjectId, $iAuthorId = 0, $iAuthorIp = 0)
  3284. {
  3285. if(empty($iAuthorId)) {
  3286. $iAuthorId = bx_get_logged_profile_id();
  3287. $iAuthorIp = bx_get_ip_hash(getVisitorIP());
  3288. }
  3289. return $this->_oDb->isPollPerformed($iObjectId, $iAuthorId, $iAuthorIp);
  3290. }
  3291. public function getPollPerformedValue($iObjectId, $iAuthorId = 0)
  3292. {
  3293. if(empty($iAuthorId))
  3294. $iAuthorId = bx_get_logged_profile_id();
  3295. return $this->_oDb->getPollPerformedValue($iObjectId, $iAuthorId);
  3296. }
  3297. public function onPublished($iContentId)
  3298. {
  3299. $CNF = &$this->_oConfig->CNF;
  3300. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  3301. if(!$aContentInfo)
  3302. return;
  3303. /*
  3304. * Process metas.
  3305. * Note. It's essential to process metas a the very end,
  3306. * because all data related to an entry should be already
  3307. * processed and are ready to be passed to alert.
  3308. */
  3309. $this->processMetasAdd($iContentId);
  3310. $this->alertAfterAdd($aContentInfo);
  3311. }
  3312. public function onFailed($iContentId)
  3313. {
  3314. $CNF = &$this->_oConfig->CNF;
  3315. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  3316. if(!$aContentInfo)
  3317. return;
  3318. /**
  3319. * @hooks
  3320. * @hookdef hook-bx_base_general-failed '{module_name}', 'failed' - hook after content creation when publishing was failed
  3321. * - $unit_name - module name
  3322. * - $action - equals `failed`
  3323. * - $object_id - content id
  3324. * - $sender_id - content author profile id
  3325. * - $extra_params - array of additional params with the following array keys:
  3326. * - `object_author_id` - [int] content author profile id
  3327. * @hook @ref hook-bx_base_general-failed
  3328. */
  3329. bx_alert($this->getName(), 'failed', $iContentId, $aContentInfo[$CNF['FIELD_AUTHOR']], [
  3330. 'object_author_id' => $aContentInfo[$CNF['FIELD_AUTHOR']]
  3331. ]);
  3332. }
  3333. public function onApprove($mixedContent)
  3334. {
  3335. $CNF = &$this->_oConfig->CNF;
  3336. if(!is_array($mixedContent))
  3337. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  3338. $this->alertAfterApprove($mixedContent);
  3339. $this->onPublished($mixedContent[$CNF['FIELD_ID']]);
  3340. }
  3341. public function onUpdateImage($iContentId, $sFiledName, $sFiledValue, $iProfileId = 0) {}
  3342. public function alertAfterAdd($aContentInfo) {}
  3343. public function alertAfterEdit($aContentInfo) {}
  3344. public function alertAfterApprove($aContentInfo)
  3345. {
  3346. $CNF = &$this->_oConfig->CNF;
  3347. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  3348. $sModule = $this->getName();
  3349. $aParams = $this->_alertParams($aContentInfo);
  3350. /**
  3351. * @hooks
  3352. * @hookdef hook-bx_base_general-approved '{module_name}', 'approved' - hook when module content has been approved
  3353. * - $unit_name - module name
  3354. * - $action - equals `approved`
  3355. * - $object_id - content id
  3356. * - $sender_id - not used, always `false`
  3357. * - $extra_params - array of additional params with the following array keys:
  3358. * - `source` - [string] uniq string for particular content in the following format `{module}_{content}`
  3359. * - `object_author_id` - [int] content author profile id
  3360. * @hook @ref hook-bx_base_general-approved
  3361. */
  3362. bx_alert($sModule, 'approved', $iId, false, $aParams);
  3363. }
  3364. /**
  3365. * Get array of params to be passed in Add/Edit Alert.
  3366. */
  3367. protected function _alertParams($aContentInfo)
  3368. {
  3369. $CNF = &$this->_oConfig->CNF;
  3370. $sModule = $this->_oConfig->getName();
  3371. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  3372. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  3373. return [
  3374. 'source' => $sModule . '_' . $iContentId,
  3375. 'source_mac' => $sModule . '_' . $iAuthorId . '_' . $iContentId,
  3376. 'object_author_id' => $iAuthorId
  3377. ];
  3378. }
  3379. public function processMetasAdd($iContentId)
  3380. {
  3381. return $this->processMetas('add', $iContentId);
  3382. }
  3383. public function processMetasEdit($iContentId, $oForm)
  3384. {
  3385. return $this->processMetas('edit', $iContentId, $oForm);
  3386. }
  3387. public function processMetas($aAction, $iContentId, $oForm = false)
  3388. {
  3389. $CNF = &$this->_oConfig->CNF;
  3390. if(empty($CNF['OBJECT_METATAGS']))
  3391. return false;
  3392. $aContentInfo = $this->_oDb->getContentInfoById($iContentId, true);
  3393. $bFldStatus = !empty($CNF['FIELD_STATUS']);
  3394. $bFldStatusAdmin = !empty($CNF['FIELD_STATUS_ADMIN']);
  3395. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  3396. if(!$bContentInfo)
  3397. return false;
  3398. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  3399. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_' . strtoupper($aAction)]);
  3400. if($oMetatags->locationsIsEnabled() && ($sKey = 'FIELD_LOCATION') && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  3401. $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
  3402. if(!empty($aLocation) && is_array($aLocation))
  3403. call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
  3404. }
  3405. if($oMetatags->keywordsIsEnabled() && ($sKey = 'FIELD_LABELS') && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  3406. $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
  3407. if(!empty($aLabels) && is_array($aLabels))
  3408. foreach ($aLabels as $sLabel) {
  3409. if(!preg_match("/(\pL[\pL\pN_]+)/u", $sLabel))
  3410. continue;
  3411. $oMetatags->keywordsAddOne($iContentId, $sLabel, false);
  3412. }
  3413. }
  3414. return true;
  3415. }
  3416. public function addAttachLink($aValues, $sDisplay = false)
  3417. {
  3418. $CNF = &$this->_oConfig->CNF;
  3419. if(!$sDisplay)
  3420. $sDisplay = $CNF['OBJECT_FORM_ATTACH_LINK_DISPLAY_ADD'];
  3421. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ATTACH_LINK'], $sDisplay, $this->_oTemplate);
  3422. if(!$oForm)
  3423. return array('message' => '_sys_txt_error_occured');
  3424. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  3425. $oForm->aParams['csrf']['disable'] = true;
  3426. if(!empty($oForm->aParams['db']['submit_name'])) {
  3427. $sSubmitName = $oForm->aParams['db']['submit_name'];
  3428. if(!isset($oForm->aInputs[$sSubmitName])) {
  3429. if(isset($oForm->aInputs[$CNF['FIELD_ATTACH_LINK_CONTROLS']]))
  3430. foreach($oForm->aInputs[$CNF['FIELD_ATTACH_LINK_CONTROLS']] as $mixedIndex => $aInput) {
  3431. if(!is_numeric($mixedIndex) || empty($aInput['name']) || $aInput['name'] != $sSubmitName)
  3432. continue;
  3433. $aValues[$sSubmitName] = $aInput['value'];
  3434. }
  3435. }
  3436. else
  3437. $aValues[$sSubmitName] = $oForm->aInputs[$sSubmitName]['value'];
  3438. }
  3439. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  3440. $oForm->initChecker(array(), $aValues);
  3441. if(!$oForm->isSubmittedAndValid())
  3442. return array('message' => '_sys_txt_error_occured');
  3443. return $this->_addLink($oForm);
  3444. }
  3445. public function getFormAttachLink($iContentId = 0)
  3446. {
  3447. $CNF = &$this->_oConfig->CNF;
  3448. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ATTACH_LINK'], $CNF['OBJECT_FORM_ATTACH_LINK_DISPLAY_ADD'], $this->_oTemplate);
  3449. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_attach_link_form/';
  3450. $oForm->aInputs[$CNF['FIELD_ATTACH_LINK_CONTENT_ID']]['value'] = $iContentId;
  3451. $oForm->aInputs[$CNF['FIELD_ATTACH_LINK_URL']]['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  3452. $oForm->initChecker();
  3453. if($oForm->isSubmittedAndValid())
  3454. return $this->_addLink($oForm);
  3455. return ['form' => $oForm->getCode(), 'form_id' => $oForm->id];
  3456. }
  3457. protected function _addLink(&$oForm)
  3458. {
  3459. $CNF = &$this->_oConfig->CNF;
  3460. $iUserId = $this->getUserId();
  3461. $iContentId = (int)$oForm->getCleanValue($CNF['FIELD_ATTACH_LINK_CONTENT_ID']);
  3462. $sLink = rtrim($oForm->getCleanValue('url'), '/');
  3463. $sHost = parse_url($sLink, PHP_URL_HOST);
  3464. if($sHost && is_private_ip(gethostbyname($sHost)))
  3465. return ['message' => _t('_sys_txt_error_occured')];
  3466. $aMatches = [];
  3467. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  3468. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  3469. $aSiteInfo = bx_get_site_info($sLink, [
  3470. 'thumbnailUrl' => ['tag' => 'link', 'content_attr' => 'href'],
  3471. 'OGImage' => ['name_attr' => 'property', 'name' => 'og:image'],
  3472. ]);
  3473. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : $sHost;
  3474. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : '';
  3475. $sMediaUrl = '';
  3476. if(!empty($aSiteInfo['thumbnailUrl']))
  3477. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  3478. else if(!empty($aSiteInfo['OGImage']))
  3479. $sMediaUrl = $aSiteInfo['OGImage'];
  3480. $iMediaId = 0;
  3481. $oStorage = null;
  3482. if(!empty($sMediaUrl)) {
  3483. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  3484. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  3485. }
  3486. $iId = (int)$oForm->insert(['profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()]);
  3487. if(!empty($iId)) {
  3488. if(!empty($oStorage) && !empty($iMediaId))
  3489. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  3490. return [
  3491. 'id' => $iId,
  3492. $CNF['FIELD_ATTACH_LINK_CONTENT_ID'] => $iContentId,
  3493. 'url' => $sLink,
  3494. 'item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId)
  3495. ];
  3496. }
  3497. return ['message' => _t('_bx_timeline_txt_err_cannot_perform_action')];
  3498. }
  3499. public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
  3500. {
  3501. if(empty($aTranscoders))
  3502. $aTranscoders = array('OBJECT_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY');
  3503. $CNF = &$this->_oConfig->CNF;
  3504. if(empty($CNF[$sField]) || empty($aContentInfo[$CNF[$sField]]) || empty($CNF['OBJECT_STORAGE']))
  3505. return false;
  3506. $iId = (int)$aContentInfo[$CNF[$sField]];
  3507. $aFile = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE'])->getFile($iId);
  3508. if(!empty($aFile) && is_array($aFile) && strpos($aFile['mime_type'], 'svg') !== false)
  3509. return array('id' => $iId, 'object' => $CNF['OBJECT_STORAGE']);
  3510. foreach($aTranscoders as $sTranscoder)
  3511. if(!empty($CNF[$sTranscoder]))
  3512. return array('id' => $iId, 'transcoder' => $CNF[$sTranscoder]);
  3513. return array('id' => $iId, 'object' => $CNF['OBJECT_STORAGE']);
  3514. }
  3515. public function getEntryAllActions ($mixedContent = false, $aParams = [])
  3516. {
  3517. $CNF = &$this->_oConfig->CNF;
  3518. if(!empty($mixedContent)) {
  3519. if(!is_array($mixedContent))
  3520. $mixedContent = array((int)$mixedContent, (method_exists($this->_oDb, 'getContentInfoById')) ? $this->_oDb->getContentInfoById((int)$mixedContent) : array());
  3521. }
  3522. else {
  3523. $mixedContent = $this->_getContent();
  3524. if($mixedContent === false)
  3525. return false;
  3526. }
  3527. list($iContentId, $aContentInfo) = $mixedContent;
  3528. $sObjectMenu = !empty($aParams['object_menu']) ? $aParams['object_menu'] : '';
  3529. if(empty($sObjectMenu) && !empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']))
  3530. $sObjectMenu = $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL'];
  3531. if(empty($sObjectMenu))
  3532. return false;
  3533. $sEntryTitle = !empty($aParams['entry_title']) ? $aParams['entry_title'] : '';
  3534. if(empty($sEntryTitle) && !empty($CNF['FIELD_TITLE']) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  3535. $sEntryTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  3536. $sEntryUrl = !empty($aParams['entry_url']) ? $aParams['entry_url'] : '';
  3537. if(empty($sEntryUrl) && !empty($CNF['URI_VIEW_ENTRY']))
  3538. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId));
  3539. $iEntryThumb = !empty($aParams['entry_thumb']) ? (int)$aParams['entry_thumb'] : 0;
  3540. if(empty($iEntryThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  3541. $iEntryThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  3542. $sObjectStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : false;
  3543. if(empty($sObjectStorage) && !empty($CNF['OBJECT_STORAGE']))
  3544. $sObjectStorage = $CNF['OBJECT_STORAGE'];
  3545. $sObjectTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : false;
  3546. $aMarkers = [
  3547. 'id' => $iContentId,
  3548. 'module' => $this->_oConfig->getName(),
  3549. 'title' => !empty($sEntryTitle) ? $sEntryTitle : '',
  3550. 'url' => !empty($sEntryUrl) ? $sEntryUrl : '',
  3551. 'img_url' => ''
  3552. ];
  3553. if(!empty($iEntryThumb)) {
  3554. if(!empty($sObjectTranscoder))
  3555. $o = BxDolTranscoder::getObjectInstance($sObjectTranscoder);
  3556. else if(!empty($sObjectStorage))
  3557. $o = BxDolStorage::getObjectInstance($sObjectStorage);
  3558. $sImageUrl = $o ? $o->getFileUrlById($iEntryThumb) : '';
  3559. if(!empty($sImageUrl))
  3560. $aMarkers['img_url'] = $sImageUrl;
  3561. }
  3562. $oActions = BxDolMenu::getObjectInstance($sObjectMenu, $this->_oTemplate);
  3563. if(!$oActions)
  3564. return false;
  3565. $oActions->setContentId($iContentId);
  3566. $oActions->addMarkers($aMarkers);
  3567. return $oActions->{bx_is_api() ? 'getCodeAPI' : 'getCode'}();
  3568. }
  3569. public function setProfileId($i)
  3570. {
  3571. $iOldProfileId = $this->_iProfileId;
  3572. $this->_iProfileId = $i;
  3573. return $iOldProfileId;
  3574. }
  3575. public function getProfileId()
  3576. {
  3577. return $this->_iProfileId;
  3578. }
  3579. public function getProfileInfo($iUserId = false)
  3580. {
  3581. $oProfile = $this->getObjectUser($iUserId);
  3582. $oAccount = null;
  3583. if($oProfile && !($oProfile instanceof BxDolProfileUndefined) && !($oProfile instanceof BxDolProfileAnonymous))
  3584. $oAccount = $oProfile->getAccountObject();
  3585. $bAccount = !empty($oAccount);
  3586. if(!$bAccount)
  3587. $oProfile = BxDolProfileUndefined::getInstance();
  3588. return array(
  3589. 'id' => $oProfile->id(),
  3590. 'name' => $oProfile->getDisplayName(),
  3591. 'email' => $bAccount ? $oAccount->getEmail() : '',
  3592. 'link' => $oProfile->getUrl(),
  3593. 'icon' => $oProfile->getIcon(),
  3594. 'thumb' => $oProfile->getThumb(),
  3595. 'avatar' => $oProfile->getAvatar(),
  3596. 'active' => $oProfile->isActive(),
  3597. );
  3598. }
  3599. public function getObjectUser($iUserId = false)
  3600. {
  3601. bx_import('BxDolProfile');
  3602. return BxDolProfile::getInstanceMagic($iUserId);
  3603. }
  3604. public function getObjectFavorite($sSystem = '', $iId = 0)
  3605. {
  3606. $CNF = &$this->_oConfig->CNF;
  3607. if(empty($sSystem) && !empty($CNF['OBJECT_FAVORITES']))
  3608. $sSystem = $CNF['OBJECT_FAVORITES'];
  3609. if(empty($sSystem))
  3610. return false;
  3611. $oFavorite = BxDolFavorite::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3612. if(!$oFavorite || !$oFavorite->isEnabled())
  3613. return false;
  3614. return $oFavorite;
  3615. }
  3616. public function getUserId()
  3617. {
  3618. return isLogged() ? bx_get_logged_profile_id() : 0;
  3619. }
  3620. public function getUserIp()
  3621. {
  3622. return getVisitorIP();
  3623. }
  3624. public function getUserInfo($iUserId = 0)
  3625. {
  3626. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  3627. return array(
  3628. $oProfile->getDisplayName(),
  3629. $oProfile->getUrl(),
  3630. $oProfile->getThumb(),
  3631. $oProfile->getUnit(),
  3632. $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  3633. );
  3634. }
  3635. public function getUserInfoWithBadges($iUserId = 0)
  3636. {
  3637. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  3638. return array(
  3639. $oProfile->getDisplayName(),
  3640. $oProfile->getUrl(),
  3641. $oProfile->getThumb(),
  3642. $oProfile->getUnit(),
  3643. $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  3644. $oProfile->getBadges()
  3645. );
  3646. }
  3647. public function isMenuItemVisible($sObject, &$aItem, &$aContentInfo)
  3648. {
  3649. $CNF = &$this->_oConfig->CNF;
  3650. // default visible settings
  3651. if(!BxDolAcl::getInstance()->isMemberLevelInSet($aItem['visible_for_levels']))
  3652. return false;
  3653. if (!empty($aItem['visibility_custom'])) {
  3654. $oMenu = BxDolMenu::getObjectInstance($sObject);
  3655. if ($oMenu && !BxDolService::callSerialized($aItem['visibility_custom'], $oMenu->getMarkers()))
  3656. return false;
  3657. }
  3658. // get custom function name to check menu item visibility
  3659. $sFuncCheckAccess = false;
  3660. if(isset($CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']]))
  3661. $sFuncCheckAccess = $CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']];
  3662. // check custom visibility settings defined in module config class
  3663. if(!isset($aContentInfo))
  3664. $aContentInfo = array();
  3665. if($sFuncCheckAccess && CHECK_ACTION_RESULT_ALLOWED !== call_user_func_array(array($this, $sFuncCheckAccess), array(&$aContentInfo)))
  3666. return false;
  3667. return true;
  3668. }
  3669. public function getModerators($mixedContentInfo)
  3670. {
  3671. $CNF = &$this->_oConfig->CNF;
  3672. $sModule = $this->_oConfig->getName();
  3673. if(!is_array($mixedContentInfo))
  3674. $mixedContentInfo = $this->_oDb->getContentInfoById((int)$mixedContentInfo);
  3675. $aModerators = [];
  3676. if(getParam('sys_notify_to_approve_by_role') == 'on' && bx_srv('system', 'is_module_content', [$sModule]) && ($sField = 'FIELD_ALLOW_VIEW_TO') && !empty($CNF[$sField]) && (int)$mixedContentInfo[$CNF[$sField]] < 0) {
  3677. $iContextProfileId = abs((int)$mixedContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
  3678. $oContextProfile = BxDolProfile::getInstance($iContextProfileId);
  3679. $aModerators = bx_srv($oContextProfile->getModule(), 'get_admins_to_manage_content', [$iContextProfileId]);
  3680. }
  3681. if(empty($aModerators))
  3682. $aModerators = BxDolAclQuery::getInstance()->getProfilesByAction([
  3683. MEMBERSHIP_ACTION_EDIT_ANY_ENTRY,
  3684. MEMBERSHIP_ACTION_DELETE_ANY_ENTRY
  3685. ], [
  3686. 'module' => $sModule,
  3687. 'ids_only' => true
  3688. ]);
  3689. return $aModerators;
  3690. }
  3691. public function _isModerator ($isPerformAction = false)
  3692. {
  3693. return $this->_isModeratorForProfile($isPerformAction, $this->_iProfileId);
  3694. }
  3695. public function _isModeratorForProfile($isPerformAction = false, $iProfileId = false)
  3696. {
  3697. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntryForProfile ($isPerformAction, $iProfileId);
  3698. }
  3699. public function _isAdministrator ($isPerformAction = false)
  3700. {
  3701. return $this->_isAdministratorForProfile($isPerformAction, $this->_iProfileId);
  3702. }
  3703. public function _isAdministratorForProfile($isPerformAction = false, $iProfileId = false)
  3704. {
  3705. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedDeleteAnyEntryForProfile ($isPerformAction, $iProfileId);
  3706. }
  3707. public function _prepareAuditParams($aContentInfo, $bIsSaveData = true, $aOverrideAuditParams = array())
  3708. {
  3709. $CNF = &$this->_oConfig->CNF;
  3710. $iContextId = isset($CNF['FIELD_ALLOW_VIEW_TO']) && (!empty($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) ? - $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] : 0;
  3711. $AuditParams = array(
  3712. 'content_title' => (isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']])) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  3713. 'context_profile_id' => $iContextId,
  3714. 'content_info_object' => isset($CNF['OBJECT_CONTENT_INFO']) ? $CNF['OBJECT_CONTENT_INFO'] : '',
  3715. 'data' => ($bIsSaveData ? $aContentInfo : array())
  3716. );
  3717. if ($iContextId > 0)
  3718. $AuditParams['context_profile_title'] = BxDolProfile::getInstance($iContextId)->getDisplayName();
  3719. $AuditParams = array_merge($AuditParams, $aOverrideAuditParams);
  3720. return $AuditParams;
  3721. }
  3722. public function _getFavoriteListUrl ($iListId, $iProfileId)
  3723. {
  3724. $CNF = &$this->_oConfig->CNF;
  3725. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_FAVORITES_LIST'] . '&profile_id=' . $iProfileId . '&list_id=' . $iListId));
  3726. }
  3727. public function getDataAPI($aData, $aParams = [])
  3728. {
  3729. $aDataApi = $this->decodeDataAPI($aData, $aParams);
  3730. $sModule = $this->getName();
  3731. $aExtras = [
  3732. 'module' => $sModule,
  3733. 'data' => $aData,
  3734. 'params' => $aParams,
  3735. 'data_api' => &$aDataApi,
  3736. 'data_api_ref' => &$aDataApi,
  3737. ];
  3738. /**
  3739. * @hooks
  3740. * @hookdef hook-system-decode_data_api 'system', 'decode_data_api' - hook to override content data prepared for sending in API response
  3741. * - $unit_name - equals `system`
  3742. * - $action - equals `decode_data_api`
  3743. * - $object_id - not used
  3744. * - $sender_id - not used
  3745. * - $extra_params - array of additional params with the following array keys:
  3746. * - `module` - [string] module name
  3747. * - `data` - [array] content info array as key&value pairs
  3748. * - `params` - [array] params array as key&value pairs
  3749. * - `data_api` - [array] by ref, content data prepared for sending in API response, can be overridden in hook processing
  3750. * @hook @ref hook-system-decode_data_api
  3751. */
  3752. bx_alert('system', 'decode_data_api', 0, 0, $aExtras);
  3753. /**
  3754. * @hooks
  3755. * @hookdef hook-bx_base_general-decode_data_api '{module_name}', 'decode_data_api' - hook to override content data prepared for sending in API response
  3756. * It's equivalent to @ref hook-system-decode_data_api
  3757. * @hook @ref hook-bx_base_general-decode_data_api
  3758. */
  3759. bx_alert($sModule, 'decode_data_api', 0, 0, $aExtras);
  3760. return $aDataApi;
  3761. }
  3762. public function decodeDataAPI($aData, $aParams = [])
  3763. {
  3764. return $aData;
  3765. }
  3766. protected function decodeDataAPICommonFields(&$aResult, $aData, $aParams)
  3767. {
  3768. $CNF = &$this->_oConfig->CNF;
  3769. if (!empty($CNF['FIELD_LABELS'])) {
  3770. $aResult[$CNF['FIELD_LABELS']] = empty($aData[$CNF['FIELD_LABELS']]) ? [] : unserialize($aData[$CNF['FIELD_LABELS']]);
  3771. }
  3772. if (!empty($CNF['FIELD_LOCATION'])) {
  3773. $aResult[$CNF['FIELD_LOCATION']] = empty($aData[$CNF['FIELD_LOCATION']]) ? [] : unserialize($aData[$CNF['FIELD_LOCATION']]);
  3774. }
  3775. }
  3776. // ====== PROTECTED METHODS
  3777. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  3778. {
  3779. $iContentId = $this->_getContent($iContentId, false);
  3780. if($iContentId === false)
  3781. return false;
  3782. $oFormsHelper = $this->getFormsHelper();
  3783. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay, $sCheckFunction, $bErrorMsg);
  3784. }
  3785. protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
  3786. {
  3787. return $this->_serviceTemplateFuncEx($sFunc, $iContentId, array('function_get_content' => $sFuncGetContent));
  3788. }
  3789. protected function _serviceTemplateFuncEx ($sFunc, $iContentId, $aParams = array())
  3790. {
  3791. if (!isset($aParams['function_get_content']))
  3792. $aParams['function_get_content'] = 'getContentInfoById';
  3793. $mixedContent = $this->_getContent($iContentId, $aParams['function_get_content']);
  3794. if($mixedContent === false)
  3795. return false;
  3796. list($iContentId, $aContentInfo) = $mixedContent;
  3797. unset($aParams['function_get_content']);
  3798. if (!empty($aParams))
  3799. return $this->_oTemplate->$sFunc($aContentInfo, $aParams);
  3800. else
  3801. return $this->_oTemplate->$sFunc($aContentInfo);
  3802. }
  3803. protected function _getApproveForm($iContentId, $aContentInfo)
  3804. {
  3805. $CNF = &$this->_oConfig->CNF;
  3806. $sForm = 'sys_manage';
  3807. if(!empty($CNF['OBJECT_FORM_MANAGE']))
  3808. $sForm = $CNF['OBJECT_FORM_MANAGE'];
  3809. $sFormDisplay = 'sys_manage_approve';
  3810. if(!empty($CNF['OBJECT_FORM_MANAGE_APPROVE']))
  3811. $sFormDisplay = $CNF['OBJECT_FORM_MANAGE_APPROVE'];
  3812. $oForm = BxTemplFormView::getObjectInstance($sForm, $sFormDisplay);
  3813. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'approve';
  3814. $oForm->aInputs['content_id']['value'] = $iContentId;
  3815. foreach($oForm->aInputs['controls'] as $iKey => $mixedValue)
  3816. if(is_numeric($iKey) && isset($mixedValue['name']) && $mixedValue['name'] == 'do_submit')
  3817. $oForm->aInputs['controls'][$iKey]['value'] = _t('_sys_form_manage_input_do_submit_approve');
  3818. /**
  3819. * @hooks
  3820. * @hookdef hook-bx_base_general-get_approve_form '{module_name}', 'get_approve_form' - hook to override approve content form
  3821. * - $unit_name - module name
  3822. * - $action - equals `get_approve_form`
  3823. * - $object_id - not used
  3824. * - $sender_id - not used
  3825. * - $extra_params - array of additional params with the following array keys:
  3826. * - `content_id` - [int] content id
  3827. * - `content_info` - [array] content info array as key&value pairs
  3828. * - `override_result` - [object] by ref, an instance of approve content form, @see BxDolForm, can be overridden in hook processing
  3829. * @hook @ref hook-bx_base_general-get_approve_form
  3830. */
  3831. bx_alert($this->_oConfig->getName(), 'get_approve_form', 0, 0, [
  3832. 'content_id' => $iContentId,
  3833. 'content_info' => $aContentInfo,
  3834. 'override_result' => &$oForm
  3835. ]);
  3836. return $oForm;
  3837. }
  3838. protected function _sendApproveMessage($iContentId, $aContentInfo, &$oForm)
  3839. {
  3840. $CNF = &$this->_oConfig->CNF;
  3841. $sETemplate = 't_ManageApprove';
  3842. if(!empty($CNF['ETEMPLATE_MANAGE_APPROVE']))
  3843. $sETemplate = $CNF['ETEMPLATE_MANAGE_APPROVE'];
  3844. $aEParams = array(
  3845. 'content_title' => !empty($CNF['FIELD_TITLE']) && !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  3846. 'notes' => $oForm->getCleanValue('notes'),
  3847. );
  3848. /**
  3849. * @hooks
  3850. * @hookdef hook-bx_base_general-get_approve_message '{module_name}', 'get_approve_form' - hook to override approve content message
  3851. * - $unit_name - module name
  3852. * - $action - equals `get_approve_message`
  3853. * - $object_id - not used
  3854. * - $sender_id - not used
  3855. * - $extra_params - array of additional params with the following array keys:
  3856. * - `content_id` - [int] content id
  3857. * - `content_info` - [array] content info array as key&value pairs
  3858. * - `form` - [object] an instance of approve content form
  3859. * - `email_template` - [string] by ref, email template name, @see BxDolEmailTemplates, can be overridden in hook processing
  3860. * - `email_params` - [array] by ref, email template params, can be overridden in hook processing
  3861. * @hook @ref hook-bx_base_general-get_approve_message
  3862. */
  3863. bx_alert($this->_oConfig->getName(), 'get_approve_message', 0, 0, [
  3864. 'content_id' => $iContentId,
  3865. 'content_info' => $aContentInfo,
  3866. 'form' => $oForm,
  3867. 'email_template' => &$sETemplate,
  3868. 'email_params' => &$aEParams,
  3869. 'email_template_ref' => &$sETemplate,
  3870. 'email_params_ref' => &$aEParams
  3871. ]);
  3872. return sendMailTemplate($sETemplate, 0, $aContentInfo[$CNF['FIELD_AUTHOR']], $aEParams);
  3873. }
  3874. protected function _processModerationNotifications($aContentInfo)
  3875. {
  3876. $CNF = &$this->_oConfig->CNF;
  3877. if(empty($CNF['PARAM_AUTO_APPROVE']) || getParam($CNF['PARAM_AUTO_APPROVE']) == 'on')
  3878. return;
  3879. $aRecipients = $this->getModerators($aContentInfo);
  3880. if(empty($aRecipients))
  3881. return;
  3882. $sModule = $this->_oConfig->getName();
  3883. foreach($aRecipients as $iRecipientId)
  3884. /**
  3885. * @hooks
  3886. * @hookdef hook-bx_base_general-pending_approval '{module_name}', 'pending_approval' - hook to notify admins/moderators about new pending approval content
  3887. * - $unit_name - module name
  3888. * - $action - equals `pending_approval`
  3889. * - $object_id - content id
  3890. * - $sender_id - content author profile id
  3891. * - $extra_params - array of additional params with the following array keys:
  3892. * - `object_author_id` - [int] admin/moderator profile id
  3893. * @hook @ref hook-bx_base_general-pending_approval
  3894. */
  3895. bx_alert($sModule, 'pending_approval', $aContentInfo[$CNF['FIELD_ID']], $aContentInfo[$CNF['FIELD_AUTHOR']], [
  3896. 'object_author_id' => (int)$iRecipientId
  3897. ]);
  3898. }
  3899. protected function _rss ($aArgs, $sClass = 'SearchResult')
  3900. {
  3901. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
  3902. $this->_oTemplate->displayAccessDenied ($sMsg);
  3903. exit;
  3904. }
  3905. $sMode = array_shift($aArgs);
  3906. $aParams = $this->_buildRssParams($sMode, $aArgs);
  3907. $o = $this->getObjectBrowse($sMode, $aParams, $sClass);
  3908. if ($o->isError)
  3909. $this->_oTemplate->displayPageNotFound ();
  3910. else
  3911. $o->outputRSS();
  3912. exit;
  3913. }
  3914. protected function _getContent($iContentId = 0, $sFuncGetContent = true)
  3915. {
  3916. if(!$iContentId)
  3917. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  3918. if(!$iContentId)
  3919. return false;
  3920. if($sFuncGetContent === true)
  3921. $sFuncGetContent = 'getContentInfoById';
  3922. if(empty($sFuncGetContent) || !method_exists($this->_oDb, $sFuncGetContent))
  3923. return $iContentId;
  3924. $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
  3925. if(!$aContentInfo)
  3926. return false;
  3927. return array($iContentId, $aContentInfo);
  3928. }
  3929. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  3930. {
  3931. $CNF = &$this->_oConfig->CNF;
  3932. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]));
  3933. //--- Image(s)
  3934. $aImages = $this->_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  3935. $aImagesAttach = $this->_getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  3936. //--- Video(s)
  3937. $aVideos = $this->_getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  3938. $aVideosAttach = $this->_getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  3939. //--- Files(s)
  3940. $aFiles = $this->_getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  3941. $aFilesAttach = $this->_getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  3942. if($this->_bIsApi && getParam('sys_api_extended_units') != 'on') {
  3943. $sTitle = '';
  3944. if(isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]))
  3945. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  3946. else if(isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]))
  3947. $sTitle = strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  3948. $sAbstract = isset($CNF['FIELD_ABSTRACT']) && isset($aContentInfo[$CNF['FIELD_ABSTRACT']]) ? $aContentInfo[$CNF['FIELD_ABSTRACT']] : '';
  3949. $sText = isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  3950. $sText = BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($sText), 240);
  3951. $aResults = [
  3952. 'url' => $sUrl,
  3953. 'title' => $sTitle,
  3954. 'abstract' => $sAbstract,
  3955. 'text' => $sText
  3956. ];
  3957. if(!empty($aImages) && is_array($aImages))
  3958. $aResults['images'] = $aImages;
  3959. if(!empty($aVideos) && is_array($aVideos))
  3960. $aResults['videos'] = $aVideos;
  3961. if(!empty($aFiles) && is_array($aFiles))
  3962. $aResults['files'] = $aFiles;
  3963. return $aResults;
  3964. }
  3965. //--- Title
  3966. $sTitle = '';
  3967. if(isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]))
  3968. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  3969. else if(isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]))
  3970. $sTitle = strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  3971. //--- Text
  3972. $sText = '';
  3973. if(isset($CNF['FIELD_ABSTRACT']) && isset($aContentInfo[$CNF['FIELD_ABSTRACT']]))
  3974. $sText = $aContentInfo[$CNF['FIELD_ABSTRACT']];
  3975. if(empty($sText) && isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]))
  3976. $sText = $aContentInfo[$CNF['FIELD_TEXT']];
  3977. if(!empty($CNF['OBJECT_METATAGS']) && is_string($sText)) {
  3978. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  3979. $sText = $oMetatags->metaParse($aContentInfo[$CNF['FIELD_ID']], $sText);
  3980. }
  3981. $sCategory = '';
  3982. if (isset($CNF['OBJECT_CATEGORY']) && isset($CNF['OBJECT_CATEGORY']) && isset($aContentInfo[$CNF['FIELD_CATEGORY']])){
  3983. $oCategory = BxDolCategory::getObjectInstance($CNF['OBJECT_CATEGORY']);
  3984. if ($oCategory)
  3985. $sCategory = $oCategory->getCategoryTitle($aContentInfo[$CNF['FIELD_CATEGORY']]);
  3986. }
  3987. $aResult = [
  3988. 'title' => $sTitle,
  3989. 'text' => $sText,
  3990. 'images' => $aImages,
  3991. 'images_attach' => $aImagesAttach,
  3992. 'videos' => $aVideos,
  3993. 'videos_attach' => $aVideosAttach,
  3994. 'files' => $aFiles,
  3995. 'files_attach' => $aFilesAttach
  3996. ];
  3997. return $this->_bIsApi ? $aResult : array_merge($aResult, [
  3998. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  3999. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  4000. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  4001. 'url' => $sUrl,
  4002. 'category' => $sCategory,
  4003. ]);
  4004. }
  4005. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  4006. {
  4007. $CNF = &$this->_oConfig->CNF;
  4008. if($this->_bIsApi) {
  4009. $aResult = [];
  4010. if(isset($CNF['FIELD_COVER']) && !empty($aContentInfo[$CNF['FIELD_COVER']])) {
  4011. $aResult[] = bx_api_get_image($CNF['OBJECT_STORAGE'], (int)$aContentInfo[$CNF['FIELD_COVER']]);
  4012. }
  4013. if((($sK = $CNF['FIELD_THUMB'] ?? false) && !empty($aContentInfo[$sK])) || (($sK = $CNF['FIELD_PICTURE'] ?? false) && !empty($aContentInfo[$sK]))) {
  4014. $aResult[] = bx_api_get_image($CNF['OBJECT_STORAGE'], (int)$aContentInfo[$sK]);
  4015. }
  4016. return $aResult;
  4017. }
  4018. $iImageId = 0;
  4019. $sImageSm = $sImageMd = $sImageXl = '';
  4020. if(isset($CNF['FIELD_COVER']) && !empty($aContentInfo[$CNF['FIELD_COVER']])) {
  4021. $iImageId = (int)$aContentInfo[$CNF['FIELD_COVER']];
  4022. $sImageSm = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_MINIATURE', 'OBJECT_IMAGES_TRANSCODER_THUMB']);
  4023. $sImageMd = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB']);
  4024. $sImageXl = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_COVER']);
  4025. }
  4026. if($sImageMd == '' && (($sK = $CNF['FIELD_THUMB'] ?? false) && !empty($aContentInfo[$sK])) || (($sK = $CNF['FIELD_PICTURE'] ?? false) && !empty($aContentInfo[$sK]))) {
  4027. $iImageId = (int)$aContentInfo[$sK];
  4028. $sImageSm = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_MINIATURE', 'OBJECT_IMAGES_TRANSCODER_THUMB']);
  4029. $sImageMd = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB']);
  4030. $sImageXl = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_COVER']);
  4031. }
  4032. if(empty($sImageMd))
  4033. return [];
  4034. if($sImageSm == '')
  4035. $sImageSm = $sImageMd;
  4036. if($sImageXl == '')
  4037. $sImageXl = $sImageMd;
  4038. return [[
  4039. 'id' => $iImageId,
  4040. 'url' => $sUrl,
  4041. 'src' => $sImageMd,
  4042. 'src_small' => $sImageSm,
  4043. 'src_medium' => $sImageMd,
  4044. 'src_orig' => $sImageXl
  4045. ]];
  4046. }
  4047. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  4048. {
  4049. return array();
  4050. }
  4051. protected function _getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  4052. {
  4053. return array();
  4054. }
  4055. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  4056. {
  4057. return array();
  4058. }
  4059. protected function _getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  4060. {
  4061. return array();
  4062. }
  4063. protected function _getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  4064. {
  4065. return array();
  4066. }
  4067. protected function _entityComments ($sObject, $iId = 0)
  4068. {
  4069. if (!$iId)
  4070. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  4071. if (!$iId)
  4072. return false;
  4073. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  4074. if (!$oCmts || !$oCmts->isEnabled())
  4075. return false;
  4076. if($this->_bIsApi)
  4077. return [
  4078. 'title' => $oCmts->getCommentsBlockTitle(),
  4079. 'content' => [bx_srv('system', 'get_data_api', [['module' => $sObject, 'object_id' => $iId]], 'TemplCmtsServices')]
  4080. ];
  4081. return $oCmts->getCommentsBlock([], ['in_designbox' => false, 'show_empty' => false]);
  4082. }
  4083. protected function _getFields($iContentId)
  4084. {
  4085. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  4086. if(empty($aContentInfo))
  4087. return array();
  4088. return BxDolContentInfo::formatFields($aContentInfo);
  4089. }
  4090. protected function _getFieldValue($sField, $iContentId)
  4091. {
  4092. $CNF = &$this->_oConfig->CNF;
  4093. if(empty($CNF[$sField]))
  4094. return false;
  4095. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  4096. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  4097. return false;
  4098. return $aContentInfo[$CNF[$sField]];
  4099. }
  4100. protected function _getFieldValueThumb($sField, $iContentId, $sTranscoder = '')
  4101. {
  4102. $CNF = &$this->_oConfig->CNF;
  4103. if(empty($sTranscoder) || empty($CNF[$sField]))
  4104. return false;
  4105. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  4106. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  4107. return false;
  4108. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  4109. if(!$oImagesTranscoder)
  4110. return false;
  4111. return $oImagesTranscoder->getFileUrl($aContentInfo[$CNF[$sField]]);
  4112. }
  4113. protected function _prepareResponse($aResponse, $bAsJson = false, $aAdditional = array())
  4114. {
  4115. if(!$bAsJson)
  4116. return $aResponse;
  4117. if(!empty($aAdditional) && is_array($aAdditional))
  4118. $aResponse = array_merge($aResponse, $aAdditional);
  4119. echoJson($aResponse);
  4120. exit;
  4121. }
  4122. /**
  4123. * Blocks for lables tree browsing private functions
  4124. */
  4125. private function _getLablesBreadcrumbsArray($iLabelId, &$aBreadcrumbs)
  4126. {
  4127. $oLabel = BxDolLabel::getInstance();
  4128. $aLabel = $oLabel->getLabels(array('type' => 'id', 'id' => $iLabelId));
  4129. if ($aLabel){
  4130. $aBreadcrumbs[$aLabel['id']] = array('id' => $aLabel['id'], 'value' => $aLabel['value']);
  4131. $this->_getLablesBreadcrumbsArray($aLabel['parent'], $aBreadcrumbs);
  4132. }
  4133. }
  4134. private function _getLablesBrowseUrl($iLabelId)
  4135. {
  4136. list($sPageLink, $aPageParams) = bx_get_base_url_inline();
  4137. return BxDolPermalinks::getInstance()->permalink(bx_append_url_params($sPageLink, array_merge($aPageParams, array('label' => $iLabelId))));
  4138. }
  4139. private function _getLablesTreeLevel($aBreadcrumbs, $iParent = 0)
  4140. {
  4141. $oLabel = BxDolLabel::getInstance();
  4142. $aLabelsOutput = array();
  4143. $aLabels = $oLabel->getLabels(array('type' => 'parent', 'parent' => $iParent));
  4144. if (count($aLabels) > 0){
  4145. foreach($aLabels as $aLabel) {
  4146. $sChild = $this->_getLablesTreeLevel($aBreadcrumbs, $aLabel['id']);
  4147. $bChildPresent = $sChild != '' ? true : false;
  4148. $bIsOpen = array_key_exists($aLabel['id'], $aBreadcrumbs) ? true : false;
  4149. if (!$bIsOpen){
  4150. $sChild = '';
  4151. }
  4152. $aLabelsOutput[] = array(
  4153. 'value' => $aLabel['value'],
  4154. 'url' => $this->_getLablesBrowseUrl($aLabel['id']),
  4155. 'child' => $sChild,
  4156. 'selected' => bx_process_input(bx_get('label'), BX_DATA_INT) == $aLabel['id'] ? 'selected' : ''.$aLabel['id'],
  4157. 'bx_if:open' => array(
  4158. 'condition' => $bChildPresent && $bIsOpen,
  4159. 'content' => array()
  4160. ),
  4161. 'bx_if:can_open' => array(
  4162. 'condition' => $bChildPresent && !$bIsOpen,
  4163. 'content' => array()
  4164. )
  4165. );
  4166. }
  4167. return $this->_oTemplate->parseHtmlByName('labels_tree.html',
  4168. array(
  4169. 'bx_repeat:items' => $aLabelsOutput,
  4170. 'parent' => $iParent,
  4171. )
  4172. );
  4173. }
  4174. return '';
  4175. }
  4176. }
  4177. /** @} */