BxBaseModGeneralModule.php 186 KB

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