BxBaseModGeneralModule.php 177 KB

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