BxBaseModGeneralModule.php 102 KB

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