BxBaseModGeneralModule.php 152 KB

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