BxBaseModGeneralModule.php 150 KB

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