BxBaseModGeneralModule.php 114 KB

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