1
0

BxBaseModGeneralModule.php 125 KB

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