1
0

BxBaseModGeneralModule.php 112 KB

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