1
0

BxBaseModGeneralModule.php 190 KB

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