BxBaseModGeneralModule.php 143 KB

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