BxBaseModGeneralModule.php 151 KB

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