BxBaseModGeneralModule.php 139 KB

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