1
0

BxBaseModGeneralModule.php 148 KB

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