1
0

BxBaseModGeneralModule.php 122 KB

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