BxBaseModGeneralModule.php 105 KB

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