1
0

BxBaseModGeneralModule.php 186 KB

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