1
0

BxBaseModGeneralModule.php 102 KB

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