1
0

BxBaseModGeneralModule.php 113 KB

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