BxBaseModGeneralModule.php 143 KB

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