BxBaseModGeneralModule.php 140 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635
  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. $mixedResult = $this->_serviceEntityForm ('editDataForm', $iContentId, $sDisplay);
  999. if(!bx_is_api())
  1000. return $mixedResult;
  1001. $aResult = [];
  1002. if(is_a($mixedResult, 'BxTemplFormView'))
  1003. $aResult = ['id' => 1, 'type' => 'form', 'data' => $mixedResult->getCodeAPI(), 'request' => ['url' => '/api.php?r=' . $this->_aModule['name'] . '/entity_edit', 'immutable' => true]];
  1004. else
  1005. $aResult = $mixedResult;
  1006. return [
  1007. $aResult
  1008. ];
  1009. }
  1010. /**
  1011. * @page service Service Calls
  1012. * @section bx_base_general Base General
  1013. * @subsection bx_base_general-forms Forms
  1014. * @subsubsection bx_base_general-entity_delete entity_delete
  1015. *
  1016. * @code bx_srv('bx_posts', 'entity_delete', [...]); @endcode
  1017. *
  1018. * Get content delete form
  1019. * @param $iContentId content ID
  1020. *
  1021. * @see BxBaseModGeneralModule::serviceEntityDelete
  1022. */
  1023. /**
  1024. * @ref bx_base_general-entity_delete "entity_delete"
  1025. */
  1026. public function serviceEntityDelete ($iContentId = 0)
  1027. {
  1028. $mixedResult = $this->_serviceEntityForm ('deleteDataForm', $iContentId);
  1029. if(!bx_is_api())
  1030. return $mixedResult;
  1031. $aResult = [];
  1032. if(is_a($mixedResult, 'BxTemplFormView'))
  1033. $aResult = ['id' => 1, 'type' => 'form', 'data' => $mixedResult->getCodeAPI(), 'request' => ['url' => '/api.php?r=' . $this->_aModule['name'] . '/entity_delete', 'immutable' => true]];
  1034. else
  1035. $aResult = $mixedResult;
  1036. return [
  1037. $aResult
  1038. ];
  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_text_block entity_text_block
  1045. *
  1046. * @code bx_srv('bx_posts', 'entity_text_block', [...]); @endcode
  1047. *
  1048. * Get content text/description
  1049. * @param $iContentId content ID
  1050. *
  1051. * @see BxBaseModGeneralModule::serviceEntityTextBlock
  1052. */
  1053. /**
  1054. * @ref bx_base_general-entity_text_block "entity_text_block"
  1055. */
  1056. public function serviceEntityTextBlock ($iContentId = 0)
  1057. {
  1058. return $this->_serviceEntityForm ('viewDataEntry', $iContentId);
  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 entity_info
  1065. *
  1066. * @code bx_srv('bx_posts', 'entity_info', [...]); @endcode
  1067. *
  1068. * Get content info
  1069. * @param $iContentId content ID
  1070. *
  1071. * @see BxBaseModGeneralModule::serviceEntityInfo
  1072. */
  1073. /**
  1074. * @ref bx_base_general-entity_info "entity_info"
  1075. */
  1076. public function serviceEntityInfo ($iContentId = 0, $sDisplay = false)
  1077. {
  1078. return $this->_serviceEntityForm ('viewDataForm', $iContentId, $sDisplay);
  1079. }
  1080. /**
  1081. * @page service Service Calls
  1082. * @section bx_base_general Base General
  1083. * @subsection bx_base_general-page_blocks Page Blocks
  1084. * @subsubsection bx_base_general-entity_info_full entity_info_full
  1085. *
  1086. * @code bx_srv('bx_posts', 'entity_info_full', [...]); @endcode
  1087. *
  1088. * Get full content info
  1089. * @param $iContentId content ID
  1090. *
  1091. * @see BxBaseModGeneralModule::serviceEntityInfoFull
  1092. */
  1093. /**
  1094. * @ref bx_base_general-entity_info_full "entity_info_full"
  1095. */
  1096. public function serviceEntityInfoFull ($iContentId = 0)
  1097. {
  1098. $CNF = &$this->_oConfig->CNF;
  1099. $sDisplayName = 'OBJECT_FORM_ENTRY_DISPLAY_VIEW_FULL';
  1100. return $this->_serviceEntityForm ('viewDataForm', $iContentId, !empty($CNF[$sDisplayName]) ? $CNF[$sDisplayName] : false);
  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_info_extended entity_info_extended
  1107. *
  1108. * @code bx_srv('bx_posts', 'entity_info_extended', [...]); @endcode
  1109. *
  1110. * Get extended content info
  1111. * @param $iContentId content ID
  1112. *
  1113. * @see BxBaseModGeneralModule::serviceEntityInfoExtended
  1114. */
  1115. /**
  1116. * @ref bx_base_general-entity_info_extended "entity_info_extended"
  1117. */
  1118. public function serviceEntityInfoExtended ($iContentId = 0)
  1119. {
  1120. return $this->_serviceTemplateFunc ('entryInfo', $iContentId);
  1121. }
  1122. /**
  1123. * @page service Service Calls
  1124. * @section bx_base_general Base General
  1125. * @subsection bx_base_general-page_blocks Page Blocks
  1126. * @subsubsection bx_base_general-entity_location entity_location
  1127. *
  1128. * @code bx_srv('bx_posts', 'entity_location', [...]); @endcode
  1129. *
  1130. * Get content location
  1131. * @param $iContentId content ID
  1132. *
  1133. * @see BxBaseModGeneralModule::serviceEntityLocation
  1134. */
  1135. /**
  1136. * @ref bx_base_general-entity_location "entity_location"
  1137. */
  1138. public function serviceEntityLocation ($iContentId = 0)
  1139. {
  1140. $iContentId = $this->_getContent($iContentId, false);
  1141. if($iContentId === false)
  1142. return false;
  1143. return $this->_oTemplate->entryLocation ($iContentId);
  1144. }
  1145. /**
  1146. * @page service Service Calls
  1147. * @section bx_base_general Base General
  1148. * @subsection bx_base_general-page_blocks Page Blocks
  1149. * @subsubsection bx_base_general-entity_comments entity_comments
  1150. *
  1151. * @code bx_srv('bx_posts', 'entity_comments', [...]); @endcode
  1152. *
  1153. * Get content comments
  1154. * @param $iContentId content ID
  1155. *
  1156. * @see BxBaseModGeneralModule::serviceEntityComments
  1157. */
  1158. /**
  1159. * @ref bx_base_general-entity_comments "entity_comments"
  1160. */
  1161. public function serviceEntityComments ($iContentId = 0)
  1162. {
  1163. $CNF = &$this->_oConfig->CNF;
  1164. if(empty($CNF['OBJECT_COMMENTS']))
  1165. return '';
  1166. return $this->_entityComments($CNF['OBJECT_COMMENTS'], $iContentId);
  1167. }
  1168. /**
  1169. * @page service Service Calls
  1170. * @section bx_base_general Base General
  1171. * @subsection bx_base_general-page_blocks Page Blocks
  1172. * @subsubsection bx_base_general-entity_attachments entity_attachments
  1173. *
  1174. * @code bx_srv('bx_posts', 'entity_attachments', [...]); @endcode
  1175. *
  1176. * Get content attachments
  1177. * @param $iContentId content ID
  1178. *
  1179. * @see BxBaseModGeneralModule::serviceEntityAttachments
  1180. */
  1181. /**
  1182. * @ref bx_base_general-entity_attachments "entity_attachments"
  1183. */
  1184. public function serviceEntityAttachments ($iContentId = 0)
  1185. {
  1186. return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
  1187. }
  1188. /**
  1189. * Delete content entry
  1190. * @param $iContentId content id
  1191. * @return error message or empty string on success
  1192. */
  1193. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  1194. {
  1195. bx_import('FormsEntryHelper', $this->_aModule);
  1196. $sClass = $this->_oConfig->getClassPrefix() . 'FormsEntryHelper';
  1197. $oFormsHelper = new $sClass($this);
  1198. return $oFormsHelper->$sFuncDelete($iContentId);
  1199. }
  1200. /**
  1201. * @page service Service Calls
  1202. * @section bx_base_general Base General
  1203. * @subsection bx_base_general-menu Menu
  1204. * @subsubsection bx_base_general-my_entries_actions my_entries_actions
  1205. *
  1206. * @code bx_srv('bx_posts', 'my_entries_actions', [...]); @endcode
  1207. *
  1208. * My entries actions menu
  1209. * @param $iProfileId profiles ID,
  1210. * if omitted it try to get it from 'profile_id' GET param
  1211. *
  1212. * @see BxBaseModGeneralModule::serviceMyEntriesActions
  1213. */
  1214. /**
  1215. * @ref bx_base_general-my_entries_actions "my_entries_actions"
  1216. */
  1217. public function serviceMyEntriesActions ($iProfileId = 0)
  1218. {
  1219. $CNF = &$this->_oConfig->CNF;
  1220. if(empty($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']))
  1221. return false;
  1222. if (!$iProfileId)
  1223. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  1224. if (!$iProfileId || !($oProfile = BxDolProfile::getInstance($iProfileId)))
  1225. return false;
  1226. if ($iProfileId != $this->_iProfileId)
  1227. return false;
  1228. $oMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']);
  1229. return $oMenu ? $oMenu->getCode() : false;
  1230. }
  1231. /**
  1232. * @page service Service Calls
  1233. * @section bx_base_general Base General
  1234. * @subsection bx_base_general-menu Menu
  1235. * @subsubsection bx_base_general-entity_all_actions entity_all_actions
  1236. *
  1237. * @code bx_srv('bx_posts', 'entity_all_actions', [...]); @endcode
  1238. *
  1239. * Entry actions and social sharing actions
  1240. * @param $mixedContent content ID
  1241. * @param $aParams additional params
  1242. *
  1243. * @see BxBaseModGeneralModule::serviceEntityAllActions
  1244. */
  1245. /**
  1246. * @ref bx_base_general-entity_all_actions "entity_all_actions"
  1247. */
  1248. public function serviceEntityAllActions ($mixedContent = false, $aParams = array())
  1249. {
  1250. $mixedResult = $this->getEntryAllActions($mixedContent, $aParams);
  1251. if(bx_is_api())
  1252. return [['id' => 1, 'type' => 'actions', 'data' => $mixedResult]];
  1253. else
  1254. return $this->_oTemplate->entryAllActions($mixedResult);
  1255. }
  1256. /**
  1257. * @page service Service Calls
  1258. * @section bx_base_general Base General
  1259. * @subsection bx_base_general-menu Menu
  1260. * @subsubsection bx_base_general-entity_actions entity_actions
  1261. *
  1262. * @code bx_srv('bx_posts', 'entity_actions', [...]); @endcode
  1263. *
  1264. * Entry actions, without social sharing actions
  1265. * @param $iContentId content ID
  1266. *
  1267. * @see BxBaseModGeneralModule::serviceEntityActions
  1268. */
  1269. /**
  1270. * @ref bx_base_general-entity_actions "entity_actions"
  1271. */
  1272. public function serviceEntityActions ($iContentId = 0)
  1273. {
  1274. $iContentId = $this->_getContent($iContentId, false);
  1275. if($iContentId === false)
  1276. return false;
  1277. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  1278. return $oMenu ? $oMenu->getCode() : false;
  1279. }
  1280. /**
  1281. * @page service Service Calls
  1282. * @section bx_base_general Base General
  1283. * @subsection bx_base_general-page_blocks Page Blocks
  1284. * @subsubsection bx_base_general-entity_reports entity_reports
  1285. *
  1286. * @code bx_srv('bx_posts', 'entity_reports', [...]); @endcode
  1287. *
  1288. * Get content reports
  1289. * @param $iContentId content ID
  1290. *
  1291. * @see BxBaseModGeneralModule::serviceEntityReports
  1292. */
  1293. /**
  1294. * @ref bx_base_general-entity_reports "entity_reports"
  1295. */
  1296. public function serviceEntityReports ($iContentId = 0)
  1297. {
  1298. $mixedContent = $this->_getContent($iContentId);
  1299. list($iContentId, $aContentInfo) = $mixedContent;
  1300. if($iContentId === false)
  1301. return false;
  1302. $CNF = &$this->_oConfig->CNF;
  1303. if (!isset($CNF['OBJECT_REPORTS']) || !isset($CNF['OBJECT_NOTES']))
  1304. return false;
  1305. if(!$aContentInfo || !(BxDolAcl::getInstance()->isMemberLevelInSet(192) || (isset($CNF['FIELD_AUTHOR']) && bx_get_logged_profile_id() == $aContentInfo[$CNF['FIELD_AUTHOR']])))
  1306. return false;
  1307. $oReport = BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $iContentId, true);
  1308. if(!$oReport)
  1309. return false;
  1310. return $oReport->getReportedByWithComments($CNF['OBJECT_NOTES']);
  1311. }
  1312. /**
  1313. * @page service Service Calls
  1314. * @section bx_base_general Base General
  1315. * @subsection bx_base_general-page_blocks Page Blocks
  1316. * @subsubsection bx_base_general-reports_count_by_status reports_count_by_status
  1317. *
  1318. * @code bx_srv('bx_posts', 'reports_count_by_status', [...]); @endcode
  1319. *
  1320. * Get number of reports with specified status
  1321. * @param $iStatus status ID
  1322. *
  1323. * @see BxBaseModGeneralModule::serviceReportsCountByStatus
  1324. */
  1325. /**
  1326. * @ref bx_base_general-entity_reports "entity_reports"
  1327. */
  1328. public function serviceReportsCountByStatus ($iStatus)
  1329. {
  1330. $CNF = &$this->_oConfig->CNF;
  1331. if (!isset($CNF['OBJECT_REPORTS']) || !isset($CNF['OBJECT_NOTES']))
  1332. return false;
  1333. $oReport = BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], 0, false);
  1334. return $oReport->getCountByStatus($iStatus);
  1335. }
  1336. /**
  1337. * @page service Service Calls
  1338. * @section bx_base_general Base General
  1339. * @subsection bx_base_general-menu Menu
  1340. * @subsubsection bx_base_general-entity_social_sharing entity_social_sharing
  1341. *
  1342. * @code bx_srv('bx_posts', 'entity_social_sharing', [...]); @endcode
  1343. *
  1344. * Entry social sharing actions
  1345. * @param $mixedContent content ID or array with integer content ID and
  1346. * array with content info, or false
  1347. * @param $aParams array with additional custom params
  1348. * which may overwrite some default values
  1349. *
  1350. * @see BxBaseModGeneralModule::serviceEntitySocialSharing
  1351. */
  1352. /**
  1353. * @ref bx_base_general-entity_social_sharing "entity_social_sharing"
  1354. */
  1355. public function serviceEntitySocialSharing($mixedContent = false, $aParams = array())
  1356. {
  1357. if(!empty($mixedContent)) {
  1358. if(!is_array($mixedContent))
  1359. $mixedContent = array((int)$mixedContent, array());
  1360. }
  1361. else {
  1362. $mixedContent = $this->_getContent();
  1363. if($mixedContent === false)
  1364. return false;
  1365. }
  1366. list($iContentId, $aContentInfo) = $mixedContent;
  1367. $CNF = &$this->_oConfig->CNF;
  1368. $sUri = !empty($aParams['uri']) ? $aParams['uri'] : '';
  1369. if(empty($sUri) && !empty($CNF['URI_VIEW_ENTRY']))
  1370. $sUri = $CNF['URI_VIEW_ENTRY'];
  1371. $sUrl = !empty($sUri) ? BxDolPermalinks::getInstance()->permalink('page.php?i=' . $sUri . '&id=' . $iContentId) : '';
  1372. $sTitle = !empty($aParams['title']) ? $aParams['title'] : '';
  1373. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  1374. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  1375. $aMarkers = array(
  1376. 'id' => $iContentId,
  1377. 'module' => $this->_aModule['name'],
  1378. 'url' => bx_absolute_url($sUrl),
  1379. 'title' => $sTitle,
  1380. );
  1381. $iIdThumb = !empty($aParams['id_thumb']) ? (int)$aParams['id_thumb'] : 0;
  1382. if(empty($iIdThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  1383. $iIdThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  1384. if ($iIdThumb) {
  1385. $sTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : '';
  1386. $sStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : '';
  1387. if(empty($sStorage) && !empty($CNF['OBJECT_STORAGE']))
  1388. $sStorage = $CNF['OBJECT_STORAGE'];
  1389. if(!empty($sTranscoder))
  1390. $o = BxDolTranscoder::getObjectInstance($sTranscoder);
  1391. else if(!empty($sStorage))
  1392. $o = BxDolStorage::getObjectInstance($sStorage);
  1393. $sImgUrl = $o ? $o->getFileUrlById($iIdThumb) : '';
  1394. if($sImgUrl)
  1395. $aMarkers['img_url'] = $sImgUrl;
  1396. }
  1397. $oMenu = BxDolMenu::getObjectInstance('sys_social_sharing');
  1398. $oMenu->addMarkers($aMarkers);
  1399. $sMenu = $oMenu->getCode();
  1400. if(empty($sMenu))
  1401. return '';
  1402. return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
  1403. 'menu' => $sMenu
  1404. ));
  1405. }
  1406. /**
  1407. * Entry context block
  1408. */
  1409. public function serviceEntityContext ($iContentId = 0)
  1410. {
  1411. return $this->_serviceTemplateFunc ('entryContext', $iContentId);
  1412. }
  1413. /**
  1414. * Blocks for lables tree browsing
  1415. */
  1416. public function serviceGetLablesTree()
  1417. {
  1418. $aBreadcrumbs = array();
  1419. $this->_getLablesBreadcrumbsArray(bx_get('label'), $aBreadcrumbs);
  1420. return $this->_getLablesTreeLevel($aBreadcrumbs);
  1421. }
  1422. public function serviceGetLablesBreadcrumbs()
  1423. {
  1424. if (bx_get('label')){
  1425. $aBreadcrumbs = array();
  1426. $this->_getLablesBreadcrumbsArray(bx_process_input(bx_get('label'), BX_DATA_INT), $aBreadcrumbs);
  1427. $aLabels = array();
  1428. foreach (array_reverse($aBreadcrumbs) as $aLabel){
  1429. $aLabels[] = array(
  1430. 'value' => $aLabel['value'],
  1431. 'url' => $this->_getLablesBrowseUrl($aLabel['id'])
  1432. );
  1433. }
  1434. return $this->_oTemplate->parseHtmlByName('labels_breadcrumbs.html', array('bx_repeat:items' => $aLabels));
  1435. }
  1436. return '';
  1437. }
  1438. public function serviceBrowseByLabel()
  1439. {
  1440. $CNF = &$this->_oConfig->CNF;
  1441. if (empty($CNF['OBJECT_METATAGS']))
  1442. return '';
  1443. $sMode = 'recent';
  1444. if(bx_srv('system', 'is_module_content', [$this->_aModule['name']]))
  1445. $sMode = 'public';
  1446. $sClassSearchResult ='SearchResult';
  1447. bx_import($sClassSearchResult, $this->_aModule['name']);
  1448. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  1449. $o = new $sClass($sMode, false);
  1450. $o->setDesignBoxTemplateId(BX_DB_PADDING_DEF);
  1451. $o->setDisplayEmptyMsg(true);
  1452. $o->setAjaxPaginate(false);
  1453. $o->setUnitParams(array('context' => $sMode));
  1454. if (bx_get('label')){
  1455. $iLabelId = (int)bx_get('label');
  1456. $oLabel = BxDolLabel::getInstance();
  1457. $aLabel = $oLabel->getLabels(array('type' => 'id', 'id' => $iLabelId));
  1458. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1459. $sTmp =$oMetatags->keywordsSetSearchCondition($o, $aLabel['value']);
  1460. }
  1461. if ($o->isError)
  1462. return '';
  1463. if ($s = $o->processing())
  1464. return $s;
  1465. else
  1466. return '';
  1467. }
  1468. public function serviceBrowseByCategories($sUnitView, $bEmptyMessage, $bAjaxPaginate, $sMode, $iPerPage)
  1469. {
  1470. $CNF = &$this->_oConfig->CNF;
  1471. $sClassSearchResult ='SearchResult';
  1472. bx_import($sClassSearchResult, $this->_aModule['name']);
  1473. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  1474. $o = new $sClass($sMode, array('unit_view' => $sUnitView, 'paginate' => array('perPage' => 10, 'start' => 0, 'num' => 11)));
  1475. $o->setDesignBoxTemplateId(BX_DB_PADDING_DEF);
  1476. $o->setAjaxPaginate($bAjaxPaginate);
  1477. $o->setCategoryObject('multi');
  1478. $aCategoriesOutput = array();
  1479. $aCategories = BxDolCategories::getInstance()->getData(array('type' => 'by_module_with_num', 'module' => $this->_aModule['name']));
  1480. foreach($aCategories as $aCategory){
  1481. if ($aCategory['num'] > 0){
  1482. $o->setCustomSearchCondition(array('keyword' => $aCategory['value']));
  1483. $o->setPaginatePerPage(2);
  1484. if (!$o->isError){
  1485. $aResult = $o->processing();
  1486. if ($aResult && $aResult['content'] != '')
  1487. $aCategoriesOutput[] = array('name' => _t($aCategory['value']), 'url' => '', 'content' => $aResult['content']);
  1488. }
  1489. }
  1490. }
  1491. return $this->_oTemplate->parseHtmlByName('browse_by_categories.html', array(
  1492. 'bx_repeat:categories' => $aCategoriesOutput,
  1493. ));
  1494. }
  1495. /**
  1496. * Data for Notifications module
  1497. */
  1498. public function serviceGetNotificationsData()
  1499. {
  1500. $sModule = $this->_aModule['name'];
  1501. $sEventPrivacy = $sModule . '_allow_view_event_to';
  1502. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  1503. $sEventPrivacy = '';
  1504. $aResult = [
  1505. 'handlers' => [
  1506. ['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],
  1507. ['group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'],
  1508. ['group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted'],
  1509. ['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],
  1510. ['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],
  1511. ['group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'],
  1512. ['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],
  1513. ['group' => $sModule . '_reply', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'replyRemoved'],
  1514. ['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],
  1515. ['group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'],
  1516. ['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],
  1517. ['group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote'],
  1518. ['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],
  1519. ['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],
  1520. //--- Moderation related: For 'admins'.
  1521. ['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],
  1522. ],
  1523. 'settings' => [
  1524. ['group' => 'content', 'unit' => $sModule, 'action' => 'added', 'types' => ['follow_member', 'follow_context']],
  1525. ['group' => 'content_updated', 'unit' => $sModule, 'action' => 'approved', 'types' => ['personal']],
  1526. ['group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => ['personal', 'follow_member', 'follow_context']],
  1527. ['group' => 'reply', 'unit' => $sModule, 'action' => 'replyPost', 'types' => ['personal']],
  1528. ['group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => ['personal', 'follow_member', 'follow_context']],
  1529. ['group' => 'vote', 'unit' => $sModule . '_reactions', 'action' => 'doVote', 'types' => ['personal', 'follow_member', 'follow_context']],
  1530. ['group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => ['personal', 'follow_member', 'follow_context']],
  1531. ['group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => ['personal', 'follow_member', 'follow_context']],
  1532. //--- Moderation related: For 'admins'.
  1533. ['group' => 'action_required', 'unit' => $sModule, 'action' => 'pending_approval', 'types' => ['personal']],
  1534. ],
  1535. 'alerts' => [
  1536. ['unit' => $sModule, 'action' => 'added'],
  1537. ['unit' => $sModule, 'action' => 'edited'],
  1538. ['unit' => $sModule, 'action' => 'deleted'],
  1539. ['unit' => $sModule, 'action' => 'approved'],
  1540. ['unit' => $sModule, 'action' => 'commentPost'],
  1541. ['unit' => $sModule, 'action' => 'commentRemoved'],
  1542. ['unit' => $sModule, 'action' => 'replyPost'],
  1543. ['unit' => $sModule, 'action' => 'replyRemoved'],
  1544. ['unit' => $sModule, 'action' => 'doVote'],
  1545. ['unit' => $sModule, 'action' => 'undoVote'],
  1546. ['unit' => $sModule . '_reactions', 'action' => 'doVote'],
  1547. ['unit' => $sModule . '_reactions', 'action' => 'undoVote'],
  1548. ['unit' => $sModule, 'action' => 'doVoteUp'],
  1549. ['unit' => $sModule, 'action' => 'doVoteDown'],
  1550. //--- Moderation related: For 'admins'.
  1551. ['unit' => $sModule, 'action' => 'pending_approval'],
  1552. ]
  1553. ];
  1554. if(!empty($this->_oConfig->CNF['FIELDS_DELAYED_PROCESSING'])) {
  1555. $aResult['handlers'] = array_merge($aResult['handlers'], [
  1556. ['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' => ''],
  1557. ['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' => ''],
  1558. ]);
  1559. $aResult['settings'] = array_merge($aResult['settings'], [
  1560. ['group' => 'content_updated', 'unit' => $sModule, 'action' => 'publish_failed', 'types' => ['personal']],
  1561. ['group' => 'content_updated', 'unit' => $sModule, 'action' => 'publish_succeeded', 'types' => ['personal']],
  1562. ]);
  1563. $aResult['alerts'] = array_merge($aResult['alerts'], [
  1564. ['unit' => $sModule, 'action' => 'publish_failed'],
  1565. ['unit' => $sModule, 'action' => 'publish_succeeded'],
  1566. ]);
  1567. }
  1568. return $aResult;
  1569. }
  1570. /**
  1571. * Entry post for Notifications module
  1572. */
  1573. public function serviceGetNotificationsPost($aEvent)
  1574. {
  1575. $CNF = &$this->_oConfig->CNF;
  1576. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  1577. if(empty($aContentInfo) || !is_array($aContentInfo))
  1578. return array();
  1579. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]), '{bx_url_root}');
  1580. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1581. return array(
  1582. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1583. 'entry_url' => $sEntryUrl,
  1584. 'entry_caption' => $sEntryCaption,
  1585. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1586. 'entry_privacy' => '', //may be empty or not specified. In this case Public privacy will be used.
  1587. '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.
  1588. /*
  1589. * Custom settings for email and/or push notifications can be provided here.
  1590. * Only necessary parts of 'settings' array can be used.
  1591. *
  1592. 'settings' => array(
  1593. 'email' => array(
  1594. 'template' => '', //--- custom email template
  1595. 'markers' => '', //--- markers to parse email parts (subject, body) with
  1596. 'subject' => '' //--- custom email subject
  1597. ),
  1598. 'push' => array(
  1599. 'subject' => '' //--- custom push notification subject
  1600. )
  1601. )
  1602. */
  1603. );
  1604. }
  1605. public function serviceGetNotificationsPostPendingApproval($aEvent)
  1606. {
  1607. $aResult = $this->serviceGetNotificationsPost($aEvent);
  1608. /**
  1609. * Unset Entry Author because the notification is addressed to 'admins'.
  1610. */
  1611. if(isset($aResult['entry_author']))
  1612. unset($aResult['entry_author']);
  1613. return $aResult;
  1614. }
  1615. public function serviceGetNotificationsPostApproved($aEvent)
  1616. {
  1617. return $this->serviceGetNotificationsPost($aEvent);
  1618. }
  1619. public function serviceGetNotificationsPostPublishFailed($aEvent)
  1620. {
  1621. return $this->serviceGetNotificationsPost($aEvent);
  1622. }
  1623. public function serviceGetNotificationsPostPublishSucceeded($aEvent)
  1624. {
  1625. return $this->serviceGetNotificationsPost($aEvent);
  1626. }
  1627. /**
  1628. * Entry post comment for Notifications module
  1629. */
  1630. public function serviceGetNotificationsComment($aEvent)
  1631. {
  1632. $CNF = &$this->_oConfig->CNF;
  1633. $iContentId = (int)$aEvent['object_id'];
  1634. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1635. if(empty($aContentInfo) || !is_array($aContentInfo))
  1636. return array();
  1637. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  1638. if(!$oComment || !$oComment->isEnabled())
  1639. return array();
  1640. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]), '{bx_url_root}');
  1641. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1642. return array(
  1643. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1644. 'entry_url' => $sEntryUrl,
  1645. 'entry_caption' => $sEntryCaption,
  1646. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1647. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  1648. 'subentry_url' => bx_absolute_url($oComment->getViewUrl((int)$aEvent['subobject_id'], false), '{bx_url_root}'),
  1649. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1650. );
  1651. }
  1652. /**
  1653. * Entry post reply for Notifications module
  1654. */
  1655. public function serviceGetNotificationsReply($aEvent)
  1656. {
  1657. $CNF = &$this->_oConfig->CNF;
  1658. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], 0, false);
  1659. if(!$oComment || !$oComment->isEnabled())
  1660. return array();
  1661. $iParentId = (int)$aEvent['object_id'];
  1662. $aParentInfo = $oComment->getQueryObject()->getCommentsBy(array('type' => 'id', 'id' => $iParentId));
  1663. if(empty($aParentInfo) || !is_array($aParentInfo))
  1664. return array();
  1665. $iObjectId = (int)$aParentInfo['cmt_object_id'];
  1666. $oComment->init($iObjectId);
  1667. return array(
  1668. 'object_id' => $iObjectId,
  1669. 'entry_sample' => '_cmt_txt_sample_comment_single',
  1670. 'entry_url' => bx_absolute_url($oComment->getViewUrl($iParentId, false), '{bx_url_root}'),
  1671. 'entry_caption' => strmaxtextlen($aParentInfo['cmt_text'], 20, '...'),
  1672. 'entry_author' => (int)$aParentInfo['cmt_author_id'],
  1673. 'subentry_sample' => '_cmt_txt_sample_reply_to',
  1674. 'subentry_url' => bx_absolute_url($oComment->getViewUrl((int)$aEvent['subobject_id'], false), '{bx_url_root}'),
  1675. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1676. );
  1677. }
  1678. /**
  1679. * Entry post vote for Notifications module
  1680. */
  1681. public function serviceGetNotificationsVote($aEvent)
  1682. {
  1683. $CNF = &$this->_oConfig->CNF;
  1684. $iContentId = (int)$aEvent['object_id'];
  1685. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1686. if(empty($aContentInfo) || !is_array($aContentInfo))
  1687. return array();
  1688. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  1689. if(!$oVote || !$oVote->isEnabled())
  1690. return array();
  1691. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]), '{bx_url_root}');
  1692. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1693. return array(
  1694. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1695. 'entry_url' => $sEntryUrl,
  1696. 'entry_caption' => $sEntryCaption,
  1697. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1698. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  1699. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1700. );
  1701. }
  1702. /**
  1703. * Entry post vote for Notifications module
  1704. */
  1705. public function serviceGetNotificationsReaction($aEvent)
  1706. {
  1707. $CNF = &$this->_oConfig->CNF;
  1708. $iContentId = (int)$aEvent['object_id'];
  1709. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1710. if(empty($aContentInfo) || !is_array($aContentInfo))
  1711. return array();
  1712. $oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $iContentId);
  1713. if(!$oReaction || !$oReaction->isEnabled())
  1714. return array();
  1715. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  1716. if(empty($aSubentry) || !is_array($aSubentry))
  1717. return array();
  1718. $aSubentrySampleParams = array();
  1719. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  1720. if(!empty($aReaction['title']))
  1721. $aSubentrySampleParams[] = $aReaction['title'];
  1722. else
  1723. $aSubentrySampleParams[] = '_undefined';
  1724. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]), '{bx_url_root}');
  1725. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1726. return array(
  1727. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1728. 'entry_url' => $sEntryUrl,
  1729. 'entry_caption' => $sEntryCaption,
  1730. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1731. 'subentry_sample' => $CNF['T']['txt_sample_reaction_single'],
  1732. 'subentry_sample_params' => $aSubentrySampleParams,
  1733. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1734. );
  1735. }
  1736. /**
  1737. * Entry post score -> vote up for Notifications module
  1738. */
  1739. public function serviceGetNotificationsScoreUp($aEvent)
  1740. {
  1741. return $this->_serviceGetNotificationsScore('up', $aEvent);
  1742. }
  1743. /**
  1744. * Entry post score -> vote up for Notifications module
  1745. */
  1746. public function serviceGetNotificationsScoreDown($aEvent)
  1747. {
  1748. return $this->_serviceGetNotificationsScore('down', $aEvent);
  1749. }
  1750. protected function _serviceGetNotificationsScore($sType, $aEvent)
  1751. {
  1752. $CNF = &$this->_oConfig->CNF;
  1753. $iContentId = (int)$aEvent['object_id'];
  1754. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1755. if(empty($aContentInfo) || !is_array($aContentInfo))
  1756. return array();
  1757. $oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContentId);
  1758. if(!$oScore || !$oScore->isEnabled())
  1759. return array();
  1760. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]), '{bx_url_root}');
  1761. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1762. return array(
  1763. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1764. 'entry_url' => $sEntryUrl,
  1765. 'entry_caption' => $sEntryCaption,
  1766. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1767. 'subentry_sample' => $CNF['T']['txt_sample_score_' . $sType . '_single'],
  1768. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1769. );
  1770. }
  1771. /**
  1772. * Data for Timeline module
  1773. */
  1774. public function serviceGetTimelineData()
  1775. {
  1776. $sModule = $this->_aModule['name'];
  1777. return array(
  1778. 'handlers' => array(
  1779. 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' => ''),
  1780. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  1781. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted')
  1782. ),
  1783. 'alerts' => array(
  1784. array('unit' => $sModule, 'action' => 'added'),
  1785. array('unit' => $sModule, 'action' => 'edited'),
  1786. array('unit' => $sModule, 'action' => 'deleted'),
  1787. )
  1788. );
  1789. }
  1790. /**
  1791. * Entry post for Timeline module
  1792. */
  1793. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  1794. {
  1795. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  1796. if(empty($aContentInfo) || !is_array($aContentInfo))
  1797. return false;
  1798. $CNF = &$this->_oConfig->CNF;
  1799. if((!empty($CNF['FIELD_STATUS']) && $aContentInfo[$CNF['FIELD_STATUS']] != 'active') || (!empty($CNF['FIELD_STATUS_ADMIN']) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != 'active'))
  1800. return false;
  1801. $iUserId = $this->getUserId();
  1802. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  1803. $iAuthorIdAbs = abs($iAuthorId);
  1804. 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)
  1805. return false;
  1806. //--- Views
  1807. $oViews = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1808. $aViews = array();
  1809. if ($oViews && $oViews->isEnabled())
  1810. $aViews = array(
  1811. 'system' => $CNF['OBJECT_VIEWS'],
  1812. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1813. 'count' => $aContentInfo['views']
  1814. );
  1815. //--- Votes
  1816. $oVotes = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1817. $aVotes = array();
  1818. if ($oVotes && $oVotes->isEnabled())
  1819. $aVotes = array(
  1820. 'system' => $CNF['OBJECT_VOTES'],
  1821. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1822. 'count' => $aContentInfo['votes']
  1823. );
  1824. //--- Reactions
  1825. $oReactions = isset($CNF['OBJECT_REACTIONS']) ? BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1826. $aReactions = array();
  1827. if ($oReactions && $oReactions->isEnabled())
  1828. $aReactions = array(
  1829. 'system' => $CNF['OBJECT_REACTIONS'],
  1830. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1831. 'count' => $aContentInfo['rvotes']
  1832. );
  1833. //--- Scores
  1834. $oScores = isset($CNF['OBJECT_SCORES']) ? BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1835. $aScores = array();
  1836. if ($oScores && $oScores->isEnabled())
  1837. $aScores = array(
  1838. 'system' => $CNF['OBJECT_SCORES'],
  1839. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1840. 'score' => $aContentInfo['score']
  1841. );
  1842. //--- Reports
  1843. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1844. $aReports = array();
  1845. if ($oReports && $oReports->isEnabled())
  1846. $aReports = array(
  1847. 'system' => $CNF['OBJECT_REPORTS'],
  1848. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1849. 'count' => $aContentInfo['reports']
  1850. );
  1851. //--- Comments
  1852. $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1853. $aComments = array();
  1854. if($oCmts && $oCmts->isEnabled())
  1855. $aComments = array(
  1856. 'system' => $CNF['OBJECT_COMMENTS'],
  1857. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1858. 'count' => $aContentInfo['comments']
  1859. );
  1860. //--- Title & Description
  1861. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  1862. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  1863. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  1864. $iOwnerId = $iAuthorIdAbs;
  1865. if(isset($aEvent['object_privacy_view']) && (int)$aEvent['object_privacy_view'] < 0)
  1866. $iOwnerId = abs($aEvent['object_privacy_view']);
  1867. $bCache = true;
  1868. $aContent = $this->_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  1869. if(isset($aContent['_cache'])) {
  1870. $bCache = (bool)$aContent['_cache'];
  1871. unset($aContent['_cache']);
  1872. }
  1873. return array(
  1874. '_cache' => $bCache,
  1875. 'owner_id' => $iOwnerId,
  1876. 'object_owner_id' => $iAuthorId,
  1877. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  1878. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  1879. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  1880. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  1881. 'url' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']])),
  1882. 'content' => $aContent, //a string to display or array to parse default template before displaying.
  1883. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  1884. 'views' => $aViews,
  1885. 'votes' => $aVotes,
  1886. 'reactions' => $aReactions,
  1887. 'scores' => $aScores,
  1888. 'reports' => $aReports,
  1889. 'comments' => $aComments,
  1890. 'title' => $sTitle, //may be empty.
  1891. 'description' => '' //may be empty.
  1892. );
  1893. }
  1894. public function serviceGetTimelinePostAllowedView($aEvent)
  1895. {
  1896. $iContentId = (int)$aEvent['object_id'];
  1897. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1898. if(empty($aContentInfo) || !is_array($aContentInfo))
  1899. return _t('_sys_txt_access_denied');
  1900. return $this->serviceCheckAllowedViewForProfile($aContentInfo);
  1901. }
  1902. /**
  1903. * Check particular action permission without content
  1904. * @param $sAction action to check, for example: Browse, Add
  1905. * @param $iContentId content ID
  1906. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1907. */
  1908. public function serviceCheckAllowed($sAction, $isPerformAction = false)
  1909. {
  1910. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  1911. if (!method_exists($this, $sMethod))
  1912. return _t('_sys_request_method_not_found_cpt');
  1913. return $this->$sMethod($isPerformAction);
  1914. }
  1915. /**
  1916. * Check particular action permission with content
  1917. * @param $sAction action to check, for example: View, Edit
  1918. * @param $iContentId content ID
  1919. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1920. */
  1921. public function serviceCheckAllowedWithContent($sAction, $iContentId, $isPerformAction = false)
  1922. {
  1923. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  1924. return _t('_sys_request_page_not_found_cpt');
  1925. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  1926. if (!method_exists($this, $sMethod))
  1927. return _t('_sys_request_method_not_found_cpt');
  1928. return $this->$sMethod($aContentInfo, $isPerformAction);
  1929. }
  1930. /**
  1931. * Check particular action permission with content for specified profile
  1932. * @param $sAction action to check, for example: View, Edit
  1933. * @param $iContentId content ID
  1934. * @param $iProfileId profile ID which the permissions to be cheked for
  1935. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1936. */
  1937. public function serviceCheckAllowedWithContentForProfile($sAction, $iContentId, $iProfileId, $isPerformAction = false)
  1938. {
  1939. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  1940. return _t('_sys_request_page_not_found_cpt');
  1941. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction) . 'ForProfile';
  1942. if (!method_exists($this, $sMethod))
  1943. return _t('_sys_request_method_not_found_cpt');
  1944. return $this->$sMethod($aContentInfo, $iProfileId, $isPerformAction);
  1945. }
  1946. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  1947. {
  1948. //negative id used in comments for reports
  1949. if ($iContentId < 0)
  1950. return CHECK_ACTION_RESULT_ALLOWED;
  1951. return $this->serviceCheckAllowedWithContent('comments_view', $iContentId);
  1952. }
  1953. public function serviceCheckAllowedCommentsPost($iContentId, $sObjectComments)
  1954. {
  1955. //negative id used in comments for reports
  1956. if ($iContentId < 0)
  1957. return CHECK_ACTION_RESULT_ALLOWED;
  1958. return $this->serviceCheckAllowedWithContent('comments_post', $iContentId);
  1959. }
  1960. public function serviceGetContentOwnerProfileId ($iContentId)
  1961. {
  1962. $CNF = &$this->_oConfig->CNF;
  1963. // file owner must be author of the content or profile itself in case of profile based module
  1964. if ($iContentId) {
  1965. $sModule = $this->getName();
  1966. if ($this instanceof iBxDolProfileService && BxDolService::call($sModule, 'act_as_profile')) {
  1967. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule);
  1968. }
  1969. else {
  1970. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1971. $oProfile = $aContentInfo ? BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]) : null;
  1972. }
  1973. $iProfileId = $oProfile ? $oProfile->id() : bx_get_logged_profile_id();
  1974. }
  1975. else {
  1976. $iProfileId = bx_get_logged_profile_id();
  1977. }
  1978. return $iProfileId;
  1979. }
  1980. public function serviceGetBadges($iContentId, $bIsSingle = false, $bIsCompact = false)
  1981. {
  1982. $sModule = $this->getName();
  1983. $oBadges = BxDolBadges::getInstance();
  1984. $aBadges = $oBadges->getData(array(
  1985. 'type' => ($bIsSingle ? 'by_module&object2_single' : 'by_module&object2'),
  1986. 'module' => $sModule,
  1987. 'object_id' => $iContentId
  1988. ));
  1989. $sResult = false;
  1990. bx_alert('system', 'get_badges', 0, 0, array(
  1991. 'module' => $sModule,
  1992. 'content_id' => $iContentId,
  1993. 'is_single' => $bIsSingle,
  1994. 'is_compact' => $bIsCompact,
  1995. 'badges' => $aBadges,
  1996. 'override_result' => &$sResult
  1997. ));
  1998. if($sResult !== false)
  1999. return $sResult;
  2000. if(empty($aBadges) || !is_array($aBadges))
  2001. return '';
  2002. if($bIsSingle)
  2003. return BxDolService::call('system', 'get_badge', array($aBadges[0], $bIsCompact), 'TemplServices');
  2004. $aBadgesOutput = array();
  2005. foreach($aBadges as $aBadge)
  2006. $aBadgesOutput[] = array('badge' => BxDolService::call('system', 'get_badge', array($aBadge, $bIsCompact), 'TemplServices'));
  2007. return $this->_oTemplate->parseHtmlByName('badges.html', array(
  2008. 'bx_repeat:items' => $aBadgesOutput,
  2009. ));
  2010. }
  2011. /**
  2012. * @page service Service Calls
  2013. * @section bx_base_general Base General
  2014. * @subsection bx_base_general-page_blocks Page Blocks
  2015. * @subsubsection bx_base_general-categories_multi_list categories_multi_list
  2016. *
  2017. * @code bx_srv('bx_posts', 'categories_multi_list', [...]); @endcode
  2018. *
  2019. * Display multi-categorories block with number of posts in each category
  2020. * @param $bDisplayEmptyCats display empty categories
  2021. *
  2022. * @see BxBaseModGeneralModule::serviceCategoriesMultiList
  2023. */
  2024. /**
  2025. * @ref bx_base_general-categories_multi_list "categories_multi_list"
  2026. */
  2027. public function serviceCategoriesMultiList($bDisplayEmptyCats = true)
  2028. {
  2029. $aContextInfo = bx_get_page_info();
  2030. $mProfileContextId = false;
  2031. if ($aContextInfo !== false)
  2032. $mProfileContextId = $aContextInfo['context_profile_id'];
  2033. $oCategories = BxDolCategories::getInstance();
  2034. if ($mProfileContextId)
  2035. $aCats = $oCategories->getData([
  2036. 'type' => 'by_module&context_with_num',
  2037. 'module' => $this->getName(),
  2038. 'context_id' => $mProfileContextId
  2039. ]);
  2040. else{
  2041. $aCats = $oCategories->getData([
  2042. 'type' => 'by_module_with_num',
  2043. 'module' => $this->getName()
  2044. ]);
  2045. }
  2046. $aVars = array('bx_repeat:cats' => array());
  2047. foreach ($aCats as $oCat) {
  2048. $sValue = $oCat['value'];
  2049. $iNum = $oCat['num'];
  2050. $aVars['bx_repeat:cats'][] = array(
  2051. 'url' => $oCategories->getUrl($this->getName(), $sValue, $mProfileContextId ? '&context_id=' . $mProfileContextId : ''),
  2052. 'name' => _t($sValue),
  2053. 'value' => $sValue,
  2054. 'num' => $iNum,
  2055. );
  2056. }
  2057. if (!$aVars['bx_repeat:cats'])
  2058. return '';
  2059. return $this->_oTemplate->parseHtmlByName('category_list_multi.html', $aVars);
  2060. }
  2061. /**
  2062. * ======
  2063. * PERMISSION METHODS
  2064. * ======
  2065. */
  2066. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  2067. {
  2068. $mixedResult = $this->_serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  2069. // check alert to allow custom checks
  2070. bx_alert('system', 'check_allowed_view', 0, 0, array('module' => $this->getName(), 'content_info' => $aDataEntry, 'profile_id' => $iProfileId, 'override_result' => &$mixedResult));
  2071. return $mixedResult;
  2072. }
  2073. public function checkAllowedSetThumb ($iContentId = 0)
  2074. {
  2075. return CHECK_ACTION_RESULT_ALLOWED;
  2076. }
  2077. /**
  2078. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  2079. */
  2080. public function checkAllowedBrowse ()
  2081. {
  2082. // check alert to allow custom checks
  2083. $mixedResult = null;
  2084. bx_alert('system', 'check_allowed_browse', 0, 0, array('module' => $this->getName(), 'profile_id' => $this->_iProfileId, 'override_result' => &$mixedResult));
  2085. if($mixedResult !== null)
  2086. return $mixedResult;
  2087. return CHECK_ACTION_RESULT_ALLOWED;
  2088. }
  2089. /**
  2090. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2091. */
  2092. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  2093. {
  2094. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  2095. }
  2096. /**
  2097. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2098. */
  2099. public function checkAllowedViewForProfile ($aDataEntry, $iProfileId, $isPerformAction = false)
  2100. {
  2101. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  2102. }
  2103. /**
  2104. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2105. */
  2106. public function checkAllowedAdd ($isPerformAction = false)
  2107. {
  2108. // check ACL
  2109. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  2110. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  2111. return $aCheck[CHECK_ACTION_MESSAGE];
  2112. return CHECK_ACTION_RESULT_ALLOWED;
  2113. }
  2114. /**
  2115. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2116. */
  2117. public function checkAllowedApprove ($aDataEntry, $isPerformAction = false)
  2118. {
  2119. $CNF = &$this->_oConfig->CNF;
  2120. $sError = '_sys_txt_access_denied';
  2121. if($this->_oConfig->isAutoApproveEnabled())
  2122. return _t($sError);
  2123. if($aDataEntry[$CNF['FIELD_STATUS_ADMIN']] != BX_BASE_MOD_GENERAL_STATUS_PENDING)
  2124. return _t($sError);
  2125. // moderator always have access
  2126. if ($this->_isModerator($isPerformAction))
  2127. return CHECK_ACTION_RESULT_ALLOWED;
  2128. // check for context's admins
  2129. if (!empty($CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  2130. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$CNF['FIELD_ALLOW_VIEW_TO']]);
  2131. if ($oProfile){
  2132. $sModule = $oProfile->getModule();
  2133. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  2134. $oModule = BxDolModule::getInstance($sModule);
  2135. // check for context's extra roles with rights
  2136. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  2137. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'edit_any');
  2138. if ($bResult !== NULL) return $bResult;
  2139. }
  2140. // if allowed edit a group then allowed to edit anything inside its context
  2141. if(isset($aEntity) && $oModule->checkAllowedEdit($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  2142. return CHECK_ACTION_RESULT_ALLOWED;
  2143. }
  2144. }
  2145. }
  2146. return _t($sError);
  2147. }
  2148. /**
  2149. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2150. */
  2151. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  2152. {
  2153. // moderator and owner always have access
  2154. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || -$aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  2155. return CHECK_ACTION_RESULT_ALLOWED;
  2156. // check for context's admins
  2157. if (!empty($this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  2158. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]);
  2159. if ($oProfile){
  2160. $sModule = $oProfile->getModule();
  2161. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  2162. $oModule = BxDolModule::getInstance($sModule);
  2163. // check for context's extra roles with rights
  2164. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  2165. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'edit_any');
  2166. if ($bResult !== NULL) return $bResult;
  2167. }
  2168. // if allowed edit a group then allowed to edit anything inside its context
  2169. if(isset($aEntity) && $oModule->checkAllowedEdit($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  2170. return CHECK_ACTION_RESULT_ALLOWED;
  2171. }
  2172. }
  2173. }
  2174. return _t('_sys_txt_access_denied');
  2175. }
  2176. /**
  2177. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2178. */
  2179. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  2180. {
  2181. // moderator always has access
  2182. if ($this->_isAdministrator($isPerformAction))
  2183. return CHECK_ACTION_RESULT_ALLOWED;
  2184. // check ACL
  2185. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  2186. 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)
  2187. return CHECK_ACTION_RESULT_ALLOWED;
  2188. // check for context's admins
  2189. if (isset($this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0){
  2190. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]);
  2191. if ($oProfile){
  2192. $sModule = $oProfile->getModule();
  2193. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  2194. $oModule = BxDolModule::getInstance($sModule);
  2195. // check for context's extra roles with rights
  2196. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  2197. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'delete_any');
  2198. if ($bResult !== NULL) return $bResult;
  2199. }
  2200. // if allowed delete a group then allowed to delete anything inside its context
  2201. if(isset($aEntity) && $oModule->checkAllowedDelete($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  2202. return CHECK_ACTION_RESULT_ALLOWED;
  2203. }
  2204. }
  2205. }
  2206. return _t('_sys_txt_access_denied');
  2207. }
  2208. /**
  2209. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2210. */
  2211. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  2212. {
  2213. // admin always has access
  2214. if (isAdmin())
  2215. return CHECK_ACTION_RESULT_ALLOWED;
  2216. // check ACL
  2217. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  2218. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  2219. return $aCheck[CHECK_ACTION_MESSAGE];
  2220. return CHECK_ACTION_RESULT_ALLOWED;
  2221. }
  2222. /**
  2223. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2224. */
  2225. public function checkAllowedEditAnyEntry ($isPerformAction = false)
  2226. {
  2227. return $this->checkAllowedEditAnyEntryForProfile($isPerformAction, $this->_iProfileId);
  2228. }
  2229. /**
  2230. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2231. */
  2232. public function checkAllowedDeleteAnyEntry ($isPerformAction = false)
  2233. {
  2234. return $this->checkAllowedDeleteAnyEntryForProfile($isPerformAction, $this->_iProfileId);
  2235. }
  2236. /**
  2237. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2238. */
  2239. public function checkAllowedEditAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  2240. {
  2241. if(!$iProfileId)
  2242. $iProfileId = $this->_iProfileId;
  2243. $aCheck = checkActionModule($iProfileId, MEMBERSHIP_ACTION_EDIT_ANY_ENTRY, $this->getName(), $isPerformAction);
  2244. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2245. return CHECK_ACTION_RESULT_ALLOWED;
  2246. return _t('_sys_txt_access_denied');
  2247. }
  2248. /**
  2249. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2250. */
  2251. public function checkAllowedDeleteAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  2252. {
  2253. if(!$iProfileId)
  2254. $iProfileId = $this->_iProfileId;
  2255. $aCheck = checkActionModule($iProfileId, MEMBERSHIP_ACTION_DELETE_ANY_ENTRY, $this->getName(), $isPerformAction);
  2256. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2257. return CHECK_ACTION_RESULT_ALLOWED;
  2258. return _t('_sys_txt_access_denied');
  2259. }
  2260. /**
  2261. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  2262. */
  2263. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  2264. {
  2265. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  2266. }
  2267. /**
  2268. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  2269. */
  2270. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  2271. {
  2272. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  2273. }
  2274. protected function _serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId)
  2275. {
  2276. $CNF = &$this->_oConfig->CNF;
  2277. if(!$iProfileId)
  2278. $iProfileId = $this->_iProfileId;
  2279. if(empty($aDataEntry) || !is_array($aDataEntry))
  2280. return _t('_sys_txt_not_found');
  2281. // moderator and owner always have access
  2282. if(!empty($iProfileId) && (abs($aDataEntry[$CNF['FIELD_AUTHOR']]) == (int)$iProfileId || $this->_isModeratorForProfile($isPerformAction, $iProfileId)))
  2283. return CHECK_ACTION_RESULT_ALLOWED;
  2284. // check ACL
  2285. $aCheck = checkActionModule($iProfileId, 'view entry', $this->getName(), $isPerformAction);
  2286. if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  2287. return $aCheck[CHECK_ACTION_MESSAGE];
  2288. // check privacy
  2289. if(!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  2290. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  2291. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  2292. return _t('_sys_access_denied_to_private_content');
  2293. }
  2294. return CHECK_ACTION_RESULT_ALLOWED;
  2295. }
  2296. public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
  2297. {
  2298. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  2299. return bx_is_api() ? [['id' => 1, 'type' => 'msg', 'data' => $sMsg]] : MsgBox($sMsg);
  2300. bx_import($sClassSearchResult, $this->_aModule);
  2301. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  2302. $o = new $sClass($sMode, $aParams);
  2303. $o->setDesignBoxTemplateId($iDesignBox);
  2304. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  2305. $o->setAjaxPaginate($bAjaxPaginate);
  2306. $o->setUnitParams(array('context' => $sMode));
  2307. if (isset($aParams['condition']) && is_array($aParams['condition']))
  2308. $o->setCustomCurrentCondition($aParams['condition']);
  2309. if ($o->isError)
  2310. return '';
  2311. if ($s = $o->processing())
  2312. return bx_is_api() ? [['id' => 1, 'type' => 'browse', 'data' => $s]] : $s;
  2313. else
  2314. return '';
  2315. }
  2316. /**
  2317. * Shows a list of profiles.
  2318. */
  2319. protected function _serviceBrowseQuick($aProfiles, $iStart = 0, $iLimit = 4, $aAdditionalParams = array())
  2320. {
  2321. // get paginate object
  2322. $oPaginate = new BxTemplPaginate(array(
  2323. 'on_change_page' => "return !loadDynamicBlockAutoPaginate(this, '{start}', '{per_page}', " . bx_js_string(json_encode($aAdditionalParams)) . ");",
  2324. 'num' => count($aProfiles),
  2325. 'per_page' => $iLimit,
  2326. 'start' => $iStart,
  2327. ));
  2328. // remove last item from connection array, because we've got one more item for pagination calculations only
  2329. if (count($aProfiles) > $iLimit)
  2330. array_pop($aProfiles);
  2331. // get profiles HTML
  2332. $s = '';
  2333. foreach ($aProfiles as $mixedProfile) {
  2334. $bProfile = is_array($mixedProfile);
  2335. $oProfile = BxDolProfile::getInstance($bProfile ? (int)$mixedProfile['id'] : (int)$mixedProfile);
  2336. if(!$oProfile)
  2337. continue;
  2338. $aUnitParams = array('template' => array('name' => 'unit', 'size' => 'thumb'));
  2339. if(BxDolModule::getInstance($oProfile->getModule()) instanceof BxBaseModGroupsModule)
  2340. $aUnitParams['template']['name'] = 'unit_wo_cover';
  2341. if($bProfile && is_array($mixedProfile['info']))
  2342. $aUnitParams['template']['vars'] = $mixedProfile['info'];
  2343. $s .= $oProfile->getUnit(0, $aUnitParams);
  2344. }
  2345. $aTmplVarsPaginate = [];
  2346. if($iStart || $oPaginate->getNum() > $iLimit)
  2347. $aTmplVarsPaginate = ['paginate' => $oPaginate->getSimplePaginate()];
  2348. return $this->_oTemplate->parseHtmlByName('browse_quick.html', array(
  2349. 'code' => $s,
  2350. 'bx_if:show_paginate' => [
  2351. 'condition' => !empty($aTmplVarsPaginate),
  2352. 'content' => $aTmplVarsPaginate
  2353. ]
  2354. ));
  2355. }
  2356. // ====== COMMON METHODS
  2357. public function onPublished($iContentId)
  2358. {
  2359. $CNF = &$this->_oConfig->CNF;
  2360. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2361. if(!$aContentInfo)
  2362. return;
  2363. $aParams = $this->_alertParams($aContentInfo);
  2364. bx_alert($this->getName(), 'added', $iContentId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
  2365. }
  2366. public function onFailed($iContentId)
  2367. {
  2368. $CNF = &$this->_oConfig->CNF;
  2369. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2370. if(!$aContentInfo)
  2371. return;
  2372. $aParams = array('object_author_id' => $aContentInfo[$CNF['FIELD_AUTHOR']]);
  2373. bx_alert($this->getName(), 'failed', $iContentId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
  2374. }
  2375. public function onApprove($mixedContent)
  2376. {
  2377. $CNF = &$this->_oConfig->CNF;
  2378. if(!is_array($mixedContent))
  2379. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  2380. $this->alertAfterApprove($mixedContent);
  2381. $this->onPublished($mixedContent[$CNF['FIELD_ID']]);
  2382. }
  2383. public function alertAfterAdd($aContentInfo) {}
  2384. public function alertAfterEdit($aContentInfo) {}
  2385. public function alertAfterApprove($aContentInfo)
  2386. {
  2387. $CNF = &$this->_oConfig->CNF;
  2388. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  2389. $sModule = $this->getName();
  2390. $aParams = $this->_alertParams($aContentInfo);
  2391. bx_alert($sModule, 'approved', $iId, false, $aParams);
  2392. }
  2393. /**
  2394. * Get array of params to be passed in Add/Edit Alert.
  2395. */
  2396. protected function _alertParams($aContentInfo)
  2397. {
  2398. $CNF = &$this->_oConfig->CNF;
  2399. return [
  2400. 'source' => $this->_oConfig->getName() . '_' . (int)$aContentInfo[$CNF['FIELD_ID']],
  2401. 'object_author_id' => (int)$aContentInfo[$CNF['FIELD_AUTHOR']]
  2402. ];
  2403. }
  2404. public function processMetasAdd($iContentId)
  2405. {
  2406. $CNF = &$this->_oConfig->CNF;
  2407. if(empty($CNF['OBJECT_METATAGS']))
  2408. return false;
  2409. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2410. $bFldStatus = !empty($CNF['FIELD_STATUS']);
  2411. $bFldStatusAdmin = !empty($CNF['FIELD_STATUS_ADMIN']);
  2412. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  2413. if(!$bContentInfo)
  2414. return false;
  2415. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  2416. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']);
  2417. $sKey = 'FIELD_LOCATION';
  2418. if($oMetatags->locationsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  2419. $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
  2420. if(!empty($aLocation) && is_array($aLocation))
  2421. call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
  2422. }
  2423. $sKey = 'FIELD_LABELS';
  2424. if($oMetatags->keywordsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  2425. $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
  2426. if(!empty($aLabels) && is_array($aLabels))
  2427. foreach ($aLabels as $sLabel) {
  2428. if(!preg_match("/(\pL[\pL\pN_]+)/u", $sLabel))
  2429. continue;
  2430. $oMetatags->keywordsAddOne($iContentId, $sLabel, false);
  2431. }
  2432. }
  2433. return true;
  2434. }
  2435. public function processMetasEdit($iContentId, $oForm)
  2436. {
  2437. $CNF = &$this->_oConfig->CNF;
  2438. if(empty($CNF['OBJECT_METATAGS']))
  2439. return false;
  2440. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2441. $bFldStatus = isset($CNF['FIELD_STATUS']);
  2442. $bFldStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']);
  2443. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  2444. if(!$bContentInfo)
  2445. return false;
  2446. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  2447. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT']);
  2448. $sKey = 'FIELD_LOCATION';
  2449. if($oMetatags->locationsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  2450. $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
  2451. if(!empty($aLocation) && is_array($aLocation))
  2452. call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
  2453. }
  2454. $sKey = 'FIELD_LABELS';
  2455. if($oMetatags->keywordsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  2456. $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
  2457. if(!empty($aLabels) && is_array($aLabels))
  2458. foreach ($aLabels as $sLabel) {
  2459. if(!preg_match("/(\pL[\pL\pN_]+)/u", $sLabel))
  2460. continue;
  2461. $oMetatags->keywordsAddOne($iContentId, $sLabel, false);
  2462. }
  2463. }
  2464. return true;
  2465. }
  2466. public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
  2467. {
  2468. if(empty($aTranscoders))
  2469. $aTranscoders = array('OBJECT_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY');
  2470. $CNF = &$this->_oConfig->CNF;
  2471. if(empty($CNF[$sField]) || empty($aContentInfo[$CNF[$sField]]) || empty($CNF['OBJECT_STORAGE']))
  2472. return false;
  2473. $iId = (int)$aContentInfo[$CNF[$sField]];
  2474. $aFile = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE'])->getFile($iId);
  2475. if(!empty($aFile) && is_array($aFile) && strpos($aFile['mime_type'], 'svg') !== false)
  2476. return array('id' => $iId, 'object' => $CNF['OBJECT_STORAGE']);
  2477. foreach($aTranscoders as $sTranscoder)
  2478. if(!empty($CNF[$sTranscoder]))
  2479. return array('id' => $iId, 'transcoder' => $CNF[$sTranscoder]);
  2480. return array('id' => $iId, 'object' => $CNF['OBJECT_STORAGE']);
  2481. }
  2482. public function getEntryAllActions ($mixedContent = false, $aParams = [])
  2483. {
  2484. $CNF = &$this->_oConfig->CNF;
  2485. if(!empty($mixedContent)) {
  2486. if(!is_array($mixedContent))
  2487. $mixedContent = array((int)$mixedContent, (method_exists($this->_oDb, 'getContentInfoById')) ? $this->_oDb->getContentInfoById((int)$mixedContent) : array());
  2488. }
  2489. else {
  2490. $mixedContent = $this->_getContent();
  2491. if($mixedContent === false)
  2492. return false;
  2493. }
  2494. list($iContentId, $aContentInfo) = $mixedContent;
  2495. $sObjectMenu = !empty($aParams['object_menu']) ? $aParams['object_menu'] : '';
  2496. if(empty($sObjectMenu) && !empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']))
  2497. $sObjectMenu = $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL'];
  2498. if(empty($sObjectMenu))
  2499. return false;
  2500. $sEntryTitle = !empty($aParams['entry_title']) ? $aParams['entry_title'] : '';
  2501. if(empty($sEntryTitle) && !empty($CNF['FIELD_TITLE']) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  2502. $sEntryTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  2503. $sEntryUrl = !empty($aParams['entry_url']) ? $aParams['entry_url'] : '';
  2504. if(empty($sEntryUrl) && !empty($CNF['URI_VIEW_ENTRY']))
  2505. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId));
  2506. $iEntryThumb = !empty($aParams['entry_thumb']) ? (int)$aParams['entry_thumb'] : 0;
  2507. if(empty($iEntryThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  2508. $iEntryThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  2509. $sObjectStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : false;
  2510. if(empty($sObjectStorage) && !empty($CNF['OBJECT_STORAGE']))
  2511. $sObjectStorage = $CNF['OBJECT_STORAGE'];
  2512. $sObjectTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : false;
  2513. $aMarkers = [
  2514. 'id' => $iContentId,
  2515. 'module' => $this->_oConfig->getName(),
  2516. 'title' => !empty($sEntryTitle) ? $sEntryTitle : '',
  2517. 'url' => !empty($sEntryUrl) ? $sEntryUrl : '',
  2518. 'img_url' => ''
  2519. ];
  2520. if(!empty($iEntryThumb)) {
  2521. if(!empty($sObjectTranscoder))
  2522. $o = BxDolTranscoder::getObjectInstance($sObjectTranscoder);
  2523. else if(!empty($sObjectStorage))
  2524. $o = BxDolStorage::getObjectInstance($sObjectStorage);
  2525. $sImageUrl = $o ? $o->getFileUrlById($iEntryThumb) : '';
  2526. if(!empty($sImageUrl))
  2527. $aMarkers['img_url'] = $sImageUrl;
  2528. }
  2529. $oActions = BxDolMenu::getObjectInstance($sObjectMenu, $this->_oTemplate);
  2530. if(!$oActions)
  2531. return false;
  2532. $oActions->setContentId($iContentId);
  2533. $oActions->addMarkers($aMarkers);
  2534. return $oActions->{bx_is_api() ? 'getCodeAPI' : 'getCode'}();
  2535. }
  2536. public function getProfileId()
  2537. {
  2538. return bx_get_logged_profile_id();
  2539. }
  2540. public function getProfileInfo($iUserId = false)
  2541. {
  2542. $oProfile = $this->getObjectUser($iUserId);
  2543. $oAccount = null;
  2544. if($oProfile && !($oProfile instanceof BxDolProfileUndefined) && !($oProfile instanceof BxDolProfileAnonymous))
  2545. $oAccount = $oProfile->getAccountObject();
  2546. $bAccount = !empty($oAccount);
  2547. if(!$bAccount)
  2548. $oProfile = BxDolProfileUndefined::getInstance();
  2549. return array(
  2550. 'id' => $oProfile->id(),
  2551. 'name' => $oProfile->getDisplayName(),
  2552. 'email' => $bAccount ? $oAccount->getEmail() : '',
  2553. 'link' => $oProfile->getUrl(),
  2554. 'icon' => $oProfile->getIcon(),
  2555. 'thumb' => $oProfile->getThumb(),
  2556. 'avatar' => $oProfile->getAvatar(),
  2557. 'unit' => $oProfile->getUnit(),
  2558. 'active' => $oProfile->isActive(),
  2559. );
  2560. }
  2561. public function getObjectUser($iUserId = false)
  2562. {
  2563. bx_import('BxDolProfile');
  2564. return BxDolProfile::getInstanceMagic($iUserId);
  2565. }
  2566. public function getObjectFavorite($sSystem = '', $iId = 0)
  2567. {
  2568. $CNF = &$this->_oConfig->CNF;
  2569. if(empty($sSystem) && !empty($CNF['OBJECT_FAVORITES']))
  2570. $sSystem = $CNF['OBJECT_FAVORITES'];
  2571. if(empty($sSystem))
  2572. return false;
  2573. $oFavorite = BxDolFavorite::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2574. if(!$oFavorite || !$oFavorite->isEnabled())
  2575. return false;
  2576. return $oFavorite;
  2577. }
  2578. public function getUserId()
  2579. {
  2580. return isLogged() ? bx_get_logged_profile_id() : 0;
  2581. }
  2582. public function getUserIp()
  2583. {
  2584. return getVisitorIP();
  2585. }
  2586. public function getUserInfo($iUserId = 0)
  2587. {
  2588. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  2589. return array(
  2590. $oProfile->getDisplayName(),
  2591. $oProfile->getUrl(),
  2592. $oProfile->getThumb(),
  2593. $oProfile->getUnit(),
  2594. $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  2595. );
  2596. }
  2597. public function getUserInfoWithBadges($iUserId = 0)
  2598. {
  2599. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  2600. return array(
  2601. $oProfile->getDisplayName(),
  2602. $oProfile->getUrl(),
  2603. $oProfile->getThumb(),
  2604. $oProfile->getUnit(),
  2605. $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  2606. $oProfile->getBadges()
  2607. );
  2608. }
  2609. public function isMenuItemVisible($sObject, &$aItem, &$aContentInfo)
  2610. {
  2611. $CNF = &$this->_oConfig->CNF;
  2612. // default visible settings
  2613. if(!BxDolAcl::getInstance()->isMemberLevelInSet($aItem['visible_for_levels']))
  2614. return false;
  2615. if (!empty($aItem['visibility_custom'])) {
  2616. $oMenu = BxDolMenu::getObjectInstance($sObject);
  2617. if ($oMenu && !BxDolService::callSerialized($aItem['visibility_custom'], $oMenu->getMarkers()))
  2618. return false;
  2619. }
  2620. // get custom function name to check menu item visibility
  2621. $sFuncCheckAccess = false;
  2622. if(isset($CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']]))
  2623. $sFuncCheckAccess = $CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']];
  2624. // check custom visibility settings defined in module config class
  2625. if(!isset($aContentInfo))
  2626. $aContentInfo = array();
  2627. if($sFuncCheckAccess && CHECK_ACTION_RESULT_ALLOWED !== call_user_func_array(array($this, $sFuncCheckAccess), array(&$aContentInfo)))
  2628. return false;
  2629. return true;
  2630. }
  2631. public function _isModerator ($isPerformAction = false)
  2632. {
  2633. return $this->_isModeratorForProfile($isPerformAction, $this->_iProfileId);
  2634. }
  2635. public function _isModeratorForProfile($isPerformAction = false, $iProfileId = false)
  2636. {
  2637. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntryForProfile ($isPerformAction, $iProfileId);
  2638. }
  2639. public function _isAdministrator ($isPerformAction = false)
  2640. {
  2641. return $this->_isAdministratorForProfile($isPerformAction, $this->_iProfileId);
  2642. }
  2643. public function _isAdministratorForProfile($isPerformAction = false, $iProfileId = false)
  2644. {
  2645. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedDeleteAnyEntryForProfile ($isPerformAction, $iProfileId);
  2646. }
  2647. public function _prepareAuditParams($aContentInfo, $bIsSaveData = true, $aOverrideAuditParams = array())
  2648. {
  2649. $CNF = &$this->_oConfig->CNF;
  2650. $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;
  2651. $AuditParams = array(
  2652. 'content_title' => (isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']])) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  2653. 'context_profile_id' => $iContextId,
  2654. 'content_info_object' => isset($CNF['OBJECT_CONTENT_INFO']) ? $CNF['OBJECT_CONTENT_INFO'] : '',
  2655. 'data' => ($bIsSaveData ? $aContentInfo : array())
  2656. );
  2657. if ($iContextId > 0)
  2658. $AuditParams['context_profile_title'] = BxDolProfile::getInstance($iContextId)->getDisplayName();
  2659. $AuditParams = array_merge($AuditParams, $aOverrideAuditParams);
  2660. return $AuditParams;
  2661. }
  2662. public function _getFavoriteListUrl ($iListId, $iProfileId)
  2663. {
  2664. $CNF = &$this->_oConfig->CNF;
  2665. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_FAVORITES_LIST'] . '&profile_id=' . $iProfileId . '&list_id=' . $iListId));
  2666. }
  2667. // ====== PROTECTED METHODS
  2668. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  2669. {
  2670. $iContentId = $this->_getContent($iContentId, false);
  2671. if($iContentId === false)
  2672. return false;
  2673. bx_import('FormsEntryHelper', $this->_aModule);
  2674. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  2675. $oFormsHelper = new $sClass($this);
  2676. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay, $sCheckFunction, $bErrorMsg);
  2677. }
  2678. protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
  2679. {
  2680. return $this->_serviceTemplateFuncEx($sFunc, $iContentId, array('function_get_content' => $sFuncGetContent));
  2681. }
  2682. protected function _serviceTemplateFuncEx ($sFunc, $iContentId, $aParams = array())
  2683. {
  2684. if (!isset($aParams['function_get_content']))
  2685. $aParams['function_get_content'] = 'getContentInfoById';
  2686. $mixedContent = $this->_getContent($iContentId, $aParams['function_get_content']);
  2687. if($mixedContent === false)
  2688. return false;
  2689. list($iContentId, $aContentInfo) = $mixedContent;
  2690. unset($aParams['function_get_content']);
  2691. if (!empty($aParams))
  2692. return $this->_oTemplate->$sFunc($aContentInfo, $aParams);
  2693. else
  2694. return $this->_oTemplate->$sFunc($aContentInfo);
  2695. }
  2696. protected function _getApproveForm($iContentId, $aContentInfo)
  2697. {
  2698. $CNF = &$this->_oConfig->CNF;
  2699. $sForm = 'sys_manage';
  2700. if(!empty($CNF['OBJECT_FORM_MANAGE']))
  2701. $sForm = $CNF['OBJECT_FORM_MANAGE'];
  2702. $sFormDisplay = 'sys_manage_approve';
  2703. if(!empty($CNF['OBJECT_FORM_MANAGE_APPROVE']))
  2704. $sFormDisplay = $CNF['OBJECT_FORM_MANAGE_APPROVE'];
  2705. $oForm = BxTemplFormView::getObjectInstance($sForm, $sFormDisplay);
  2706. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'approve';
  2707. $oForm->aInputs['content_id']['value'] = $iContentId;
  2708. foreach($oForm->aInputs['controls'] as $iKey => $mixedValue)
  2709. if(is_numeric($iKey) && isset($mixedValue['name']) && $mixedValue['name'] == 'do_submit')
  2710. $oForm->aInputs['controls'][$iKey]['value'] = _t('_sys_form_manage_input_do_submit_approve');
  2711. bx_alert($this->_oConfig->getName(), 'get_approve_form', 0, 0, array(
  2712. 'content_id' => $iContentId,
  2713. 'content_info' => $aContentInfo,
  2714. 'override_result' => &$oForm
  2715. ));
  2716. return $oForm;
  2717. }
  2718. protected function _sendApproveMessage($iContentId, $aContentInfo, &$oForm)
  2719. {
  2720. $CNF = &$this->_oConfig->CNF;
  2721. $sETemplate = 't_ManageApprove';
  2722. if(!empty($CNF['ETEMPLATE_MANAGE_APPROVE']))
  2723. $sETemplate = $CNF['ETEMPLATE_MANAGE_APPROVE'];
  2724. $aEParams = array(
  2725. 'content_title' => !empty($CNF['FIELD_TITLE']) && !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  2726. 'notes' => $oForm->getCleanValue('notes'),
  2727. );
  2728. bx_alert($this->_oConfig->getName(), 'get_approve_message', 0, 0, array(
  2729. 'content_id' => $iContentId,
  2730. 'content_info' => $aContentInfo,
  2731. 'form' => $oForm,
  2732. 'email_template' => &$sETemplate,
  2733. 'email_params' => &$aEParams
  2734. ));
  2735. return sendMailTemplate($sETemplate, 0, $aContentInfo[$CNF['FIELD_AUTHOR']], $aEParams);
  2736. }
  2737. protected function _processModerationNotifications($aContentInfo)
  2738. {
  2739. $CNF = &$this->_oConfig->CNF;
  2740. if(empty($CNF['PARAM_AUTO_APPROVE']) || getParam($CNF['PARAM_AUTO_APPROVE']) == 'on')
  2741. return;
  2742. $aRecipients = [];
  2743. 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) {
  2744. $iContextProfileId = abs((int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
  2745. $oContextProfile = BxDolProfile::getInstance($iContextProfileId);
  2746. $aRecipients = bx_srv($oContextProfile->getModule(), 'get_admins_to_manage_content', [$iContextProfileId]);
  2747. }
  2748. $sModule = $this->getName();
  2749. if(empty($aRecipients))
  2750. $aRecipients = BxDolAclQuery::getInstance()->getProfilesByAction([
  2751. MEMBERSHIP_ACTION_EDIT_ANY_ENTRY,
  2752. MEMBERSHIP_ACTION_DELETE_ANY_ENTRY
  2753. ], [
  2754. 'module' => $sModule,
  2755. 'ids_only' => true
  2756. ]);
  2757. if(empty($aRecipients))
  2758. return;
  2759. foreach($aRecipients as $iRecipientId)
  2760. bx_alert($sModule, 'pending_approval', $aContentInfo[$CNF['FIELD_ID']], $aContentInfo[$CNF['FIELD_AUTHOR']], [
  2761. 'object_author_id' => (int)$iRecipientId
  2762. ]);
  2763. }
  2764. protected function _rss ($aArgs, $sClass = 'SearchResult')
  2765. {
  2766. $sMode = array_shift($aArgs);
  2767. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
  2768. $this->_oTemplate->displayAccessDenied ($sMsg);
  2769. exit;
  2770. }
  2771. $aParams = $this->_buildRssParams($sMode, $aArgs);
  2772. bx_import ($sClass, $this->_aModule);
  2773. $sClass = $this->_aModule['class_prefix'] . $sClass;
  2774. $o = new $sClass($sMode, $aParams);
  2775. if ($o->isError)
  2776. $this->_oTemplate->displayPageNotFound ();
  2777. else
  2778. $o->outputRSS();
  2779. exit;
  2780. }
  2781. protected function _getContent($iContentId = 0, $sFuncGetContent = true)
  2782. {
  2783. if(!$iContentId)
  2784. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2785. if(!$iContentId)
  2786. return false;
  2787. if($sFuncGetContent === true)
  2788. $sFuncGetContent = 'getContentInfoById';
  2789. if(empty($sFuncGetContent) || !method_exists($this->_oDb, $sFuncGetContent))
  2790. return $iContentId;
  2791. $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
  2792. if(!$aContentInfo)
  2793. return false;
  2794. return array($iContentId, $aContentInfo);
  2795. }
  2796. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  2797. {
  2798. $CNF = &$this->_oConfig->CNF;
  2799. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]));
  2800. //--- Image(s)
  2801. $aImages = $this->_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2802. $aImagesAttach = $this->_getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2803. //--- Video(s)
  2804. $aVideos = $this->_getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2805. $aVideosAttach = $this->_getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2806. //--- Files(s)
  2807. $aFiles = $this->_getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2808. $aFilesAttach = $this->_getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2809. //--- Title
  2810. $sTitle = '';
  2811. if(isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]))
  2812. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  2813. else if(isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]))
  2814. $sTitle = strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  2815. //--- Text
  2816. $sText = isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  2817. if(!empty($CNF['OBJECT_METATAGS']) && is_string($sText)) {
  2818. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  2819. $sText = $oMetatags->metaParse($aContentInfo[$CNF['FIELD_ID']], $sText);
  2820. }
  2821. return array(
  2822. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  2823. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  2824. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  2825. 'url' => $sUrl,
  2826. 'title' => $sTitle,
  2827. 'text' => $sText,
  2828. 'images' => $aImages,
  2829. 'images_attach' => $aImagesAttach,
  2830. 'videos' => $aVideos,
  2831. 'videos_attach' => $aVideosAttach,
  2832. 'files' => $aFiles,
  2833. 'files_attach' => $aFilesAttach
  2834. );
  2835. }
  2836. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2837. {
  2838. $CNF = &$this->_oConfig->CNF;
  2839. if (bx_is_api()){
  2840. $aResult = [];
  2841. if(isset($CNF['FIELD_COVER']) && !empty($aContentInfo[$CNF['FIELD_COVER']])) {
  2842. $aResult[] = bx_api_get_image($CNF['OBJECT_STORAGE'], (int)$aContentInfo[$CNF['FIELD_COVER']]);
  2843. }
  2844. if(isset($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']])) {
  2845. $aResult[] = bx_api_get_image($CNF['OBJECT_STORAGE'], (int)$aContentInfo[$CNF['FIELD_THUMB']]);
  2846. }
  2847. return $aResult;
  2848. }
  2849. else{
  2850. $iImageId = 0;
  2851. $sImageSm = $sImageMd = $sImageXl = '';
  2852. if(isset($CNF['FIELD_COVER']) && !empty($aContentInfo[$CNF['FIELD_COVER']])) {
  2853. $iImageId = (int)$aContentInfo[$CNF['FIELD_COVER']];
  2854. $sImageSm = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_MINIATURE', 'OBJECT_IMAGES_TRANSCODER_THUMB']);
  2855. $sImageMd = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB']);
  2856. $sImageXl = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_COVER']);
  2857. }
  2858. if($sImageMd == '' && isset($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']])) {
  2859. $iImageId = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  2860. $sImageSm = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_MINIATURE', 'OBJECT_IMAGES_TRANSCODER_THUMB']);
  2861. $sImageMd = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB']);
  2862. $sImageXl = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_COVER']);
  2863. }
  2864. if(empty($sImageMd))
  2865. return [];
  2866. if($sImageSm == '')
  2867. $sImageSm = $sImageMd;
  2868. if($sImageXl == '')
  2869. $sImageXl = $sImageMd;
  2870. return [[
  2871. 'id' => $iImageId,
  2872. 'url' => $sUrl,
  2873. 'src' => $sImageMd,
  2874. 'src_small' => $sImageSm,
  2875. 'src_medium' => $sImageMd,
  2876. 'src_orig' => $sImageXl
  2877. ]];
  2878. }
  2879. }
  2880. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2881. {
  2882. return array();
  2883. }
  2884. protected function _getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2885. {
  2886. return array();
  2887. }
  2888. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2889. {
  2890. return array();
  2891. }
  2892. protected function _getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2893. {
  2894. return array();
  2895. }
  2896. protected function _getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2897. {
  2898. return array();
  2899. }
  2900. protected function _entityComments ($sObject, $iId = 0)
  2901. {
  2902. if (!$iId)
  2903. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2904. if (!$iId)
  2905. return false;
  2906. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  2907. if (!$oCmts || !$oCmts->isEnabled())
  2908. return false;
  2909. if (bx_is_api()){
  2910. $aForm = $oCmts->getFormPost(0);
  2911. if (is_array($aForm)){
  2912. $aForm['id'] = 2;
  2913. }
  2914. else
  2915. $aForm = ['id' => 2, 'type' => 'form', 'name' => 'comment', 'data' => $aForm->getCodeAPI(), 'request' => ['url' => '/api.php?r=' . $this->_aModule['name'] . '/entity_comments', 'immutable' => true]];
  2916. return [
  2917. ['id' => 1, 'type' => 'browse', 'data' => $oCmts->getCommentsBlockAPI([], ['in_designbox' => false, 'show_empty' => false])],
  2918. $aForm
  2919. ];
  2920. }
  2921. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => false));
  2922. }
  2923. protected function _getFields($iContentId)
  2924. {
  2925. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2926. if(empty($aContentInfo))
  2927. return array();
  2928. return BxDolContentInfo::formatFields($aContentInfo);
  2929. }
  2930. protected function _getFieldValue($sField, $iContentId)
  2931. {
  2932. $CNF = &$this->_oConfig->CNF;
  2933. if(empty($CNF[$sField]))
  2934. return false;
  2935. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2936. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  2937. return false;
  2938. return $aContentInfo[$CNF[$sField]];
  2939. }
  2940. protected function _getFieldValueThumb($sField, $iContentId, $sTranscoder = '')
  2941. {
  2942. $CNF = &$this->_oConfig->CNF;
  2943. if(empty($sTranscoder) || empty($CNF[$sField]))
  2944. return false;
  2945. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2946. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  2947. return false;
  2948. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  2949. if(!$oImagesTranscoder)
  2950. return false;
  2951. return $oImagesTranscoder->getFileUrl($aContentInfo[$CNF[$sField]]);
  2952. }
  2953. protected function _prepareResponse($aResponse, $bAsJson = false, $aAdditional = array())
  2954. {
  2955. if(!$bAsJson)
  2956. return $aResponse;
  2957. if(!empty($aAdditional) && is_array($aAdditional))
  2958. $aResponse = array_merge($aResponse, $aAdditional);
  2959. echoJson($aResponse);
  2960. exit;
  2961. }
  2962. /**
  2963. * Blocks for lables tree browsing private functions
  2964. */
  2965. private function _getLablesBreadcrumbsArray($iLabelId, &$aBreadcrumbs)
  2966. {
  2967. $oLabel = BxDolLabel::getInstance();
  2968. $aLabel = $oLabel->getLabels(array('type' => 'id', 'id' => $iLabelId));
  2969. if ($aLabel){
  2970. $aBreadcrumbs[$aLabel['id']] = array('id' => $aLabel['id'], 'value' => $aLabel['value']);
  2971. $this->_getLablesBreadcrumbsArray($aLabel['parent'], $aBreadcrumbs);
  2972. }
  2973. }
  2974. private function _getLablesBrowseUrl($iLabelId)
  2975. {
  2976. list($sPageLink, $aPageParams) = bx_get_base_url_inline();
  2977. return BxDolPermalinks::getInstance()->permalink(bx_append_url_params($sPageLink, array_merge($aPageParams, array('label' => $iLabelId))));
  2978. }
  2979. private function _getLablesTreeLevel($aBreadcrumbs, $iParent = 0)
  2980. {
  2981. $oLabel = BxDolLabel::getInstance();
  2982. $aLabelsOutput = array();
  2983. $aLabels = $oLabel->getLabels(array('type' => 'parent', 'parent' => $iParent));
  2984. if (count($aLabels) > 0){
  2985. foreach($aLabels as $aLabel) {
  2986. $sChild = $this->_getLablesTreeLevel($aBreadcrumbs, $aLabel['id']);
  2987. $bChildPresent = $sChild != '' ? true : false;
  2988. $bIsOpen = array_key_exists($aLabel['id'], $aBreadcrumbs) ? true : false;
  2989. if (!$bIsOpen){
  2990. $sChild = '';
  2991. }
  2992. $aLabelsOutput[] = array(
  2993. 'value' => $aLabel['value'],
  2994. 'url' => $this->_getLablesBrowseUrl($aLabel['id']),
  2995. 'child' => $sChild,
  2996. 'selected' => bx_process_input(bx_get('label'), BX_DATA_INT) == $aLabel['id'] ? 'selected' : ''.$aLabel['id'],
  2997. 'bx_if:open' => array(
  2998. 'condition' => $bChildPresent && $bIsOpen,
  2999. 'content' => array()
  3000. ),
  3001. 'bx_if:can_open' => array(
  3002. 'condition' => $bChildPresent && !$bIsOpen,
  3003. 'content' => array()
  3004. )
  3005. );
  3006. }
  3007. return $this->_oTemplate->parseHtmlByName('labels_tree.html',
  3008. array(
  3009. 'bx_repeat:items' => $aLabelsOutput,
  3010. 'parent' => $iParent,
  3011. )
  3012. );
  3013. }
  3014. return '';
  3015. }
  3016. }
  3017. /** @} */